<commit_before>#include "TextureConverter.hpp"

#define STB_IMAGE_IMPLEMENTATION
#define STBI_ONLY_PNG
#include <stb_image.h>

#include <fstream>
#include <Utility/Log.hpp>
#include <Video/Texture/TextureHCT.hpp>

namespace TextureConverter {
    void Convert(const char* inFilename, const char* outFilename) {
        // Load PNG file.
        int components, width, height;
        unsigned char* data = stbi_load(inFilename, &width, &height, &components, 0);
        if (data == NULL) {
            Log(Log::ERR) << "Couldn't load image: " << inFilename << "\n";
            return;
        }
        
        // Convert to RGB (in case it's not already).
        unsigned char* rgbData = new unsigned char[width * height * 3];
        
        for (int y = 0; y < height; ++y) {
            for (int x = 0; x < width; ++x) {
                int index = y * width + x;
                rgbData[index * 3 + 0] = data[index * components + 0];
                rgbData[index * 3 + 1] = (components >= 2) ? data[index * components + 1] : 0;
                rgbData[index * 3 + 2] = (components >= 3) ? data[index * components + 2] : 0;
            }
        }
        
        stbi_image_free(data);
        
        // Store results to file.
        std::ofstream file(outFilename, std::ios::out | std::ios::binary);
        if (!file) {
            Log(Log::ERR) << "Couldn't open file: " << outFilename << "\n";
            return;
        }
        
        // Write header.
        uint16_t version = Video::TextureHCT::VERSION;
        uint16_t mipLevels = 1;
        file.write(reinterpret_cast<const char*>(&version), sizeof(uint16_t));
        file.write(reinterpret_cast<const char*>(&width), sizeof(uint16_t));
        file.write(reinterpret_cast<const char*>(&height), sizeof(uint16_t));
        file.write(reinterpret_cast<const char*>(&mipLevels), sizeof(uint16_t));
        
        // Write data.
        file.write(reinterpret_cast<char*>(rgbData), width * height * 3);
        
        file.close();
        
        delete[] rgbData;
    }
}
<commit_msg>Check that texture is multiple of 4<commit_after>#include "TextureConverter.hpp"

#define STB_IMAGE_IMPLEMENTATION
#define STBI_ONLY_PNG
#include <stb_image.h>

#include <fstream>
#include <Utility/Log.hpp>
#include <Video/Texture/TextureHCT.hpp>

namespace TextureConverter {
    void Convert(const char* inFilename, const char* outFilename) {
        // Load PNG file.
        int components, width, height;
        unsigned char* data = stbi_load(inFilename, &width, &height, &components, 0);
        if (data == NULL) {
            Log(Log::ERR) << "Couldn't load image: " << inFilename << "\n";
            return;
        }
        if (width % 4 != 0 || height % 4 != 0) {
            Log(Log::ERR) << inFilename << " does not have dimensions multiple of 4.\n";
            return;
        }
        
        // Convert to RGB (in case it's not already).
        unsigned char* rgbData = new unsigned char[width * height * 3];
        
        for (int y = 0; y < height; ++y) {
            for (int x = 0; x < width; ++x) {
                int index = y * width + x;
                rgbData[index * 3 + 0] = data[index * components + 0];
                rgbData[index * 3 + 1] = (components >= 2) ? data[index * components + 1] : 0;
                rgbData[index * 3 + 2] = (components >= 3) ? data[index * components + 2] : 0;
            }
        }
        
        stbi_image_free(data);
        
        // Store results to file.
        std::ofstream file(outFilename, std::ios::out | std::ios::binary);
        if (!file) {
            Log(Log::ERR) << "Couldn't open file: " << outFilename << "\n";
            return;
        }
        
        // Write header.
        uint16_t version = Video::TextureHCT::VERSION;
        uint16_t mipLevels = 1;
        file.write(reinterpret_cast<const char*>(&version), sizeof(uint16_t));
        file.write(reinterpret_cast<const char*>(&width), sizeof(uint16_t));
        file.write(reinterpret_cast<const char*>(&height), sizeof(uint16_t));
        file.write(reinterpret_cast<const char*>(&mipLevels), sizeof(uint16_t));
        
        // Write data.
        file.write(reinterpret_cast<char*>(rgbData), width * height * 3);
        
        file.close();
        
        delete[] rgbData;
    }
}

{'fraction_non_alphanumeric': 0.13903002309468823, 'fraction_numerical': 0.015704387990762125, 'mean_word_length': 2.0759943181818183, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 25, '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': '3814710', 'n_tokens_mistral': 1394, 'n_tokens_neox': 1309, 'n_words': 331}