<commit_before>// File: ktxtool.cpp

#include <stdlib.h>
#include <stdio.h>

#include "vogl_core.h"
#include "vogl_colorized_console.h"
#include "vogl_command_line_params.h"
#include "vogl_cfile_stream.h"
#include "vogl_ktx_texture.h"
#include "vogl_miniz.h"
#include "vogl_file_utils.h"
#include "vogl_image.h"
#include "vogl_image_utils.h"

#include <GL/gl.h>
#include "pxfmt.h"

using namespace vogl;

//----------------------------------------------------------------------------------------------------------------------
// command line params
//----------------------------------------------------------------------------------------------------------------------
static command_line_param_desc g_command_line_param_descs[] =
    {
        { "help", 0, false, "Display this help" },
        { "?", 0, false, "Display this help" },
    };

//----------------------------------------------------------------------------------------------------------------------
// tool_print_title
//----------------------------------------------------------------------------------------------------------------------
static void tool_print_title()
{
    vogl_printf("ktxtool ");
    if (sizeof(void *) > 4)
        vogl_printf("64-bit ");
    else
        vogl_printf("32-bit ");
#ifdef VOGL_BUILD_DEBUG
    vogl_printf("Debug ");
#else
    vogl_printf("Release ");
#endif
    vogl_printf("Built %s %s\n", __DATE__, __TIME__);
}

//----------------------------------------------------------------------------------------------------------------------
// tool_print_help
//----------------------------------------------------------------------------------------------------------------------
static void tool_print_help()
{
    vogl_printf("Usage: ktxtool [ -option ... ] input_file.ktx output_prefix [ -option ... ]\n");
    vogl_printf("Command line options may begin with single minus \"-\" or double minus \"--\"\n");

    vogl_printf("\nCommand line options:\n");

    dump_command_line_info(VOGL_ARRAY_SIZE(g_command_line_param_descs), g_command_line_param_descs, "--");
}

//----------------------------------------------------------------------------------------------------------------------
// init_command_line_params
//----------------------------------------------------------------------------------------------------------------------
static bool init_command_line_params(int argc, char *argv[])
{
    command_line_params::parse_config parse_cfg;
    parse_cfg.m_single_minus_params = true;
    parse_cfg.m_double_minus_params = true;

    if (!g_command_line_params().parse(get_command_line_params(argc, argv), VOGL_ARRAY_SIZE(g_command_line_param_descs), g_command_line_param_descs, parse_cfg))
    {
        vogl_error_printf("Failed parsing command line parameters!\n");
        return false;
    }

    if (g_command_line_params().get_value_as_bool("help") || g_command_line_params().get_value_as_bool("?"))
    {
        tool_print_help();
        return false;
    }

    return true;
}

//----------------------------------------------------------------------------------------------------------------------
// main
//----------------------------------------------------------------------------------------------------------------------
int main(int argc, char **argv)
{
    // Initialize vogl_core.
    vogl_core_init();

    colorized_console::init();
    colorized_console::set_exception_callback();

    tool_print_title();

    if (!init_command_line_params(argc, argv))
        return EXIT_FAILURE;

    if (g_command_line_params().get_count("") != 3)
    {
        vogl_error_printf("2 parameters required\n");
        return EXIT_FAILURE;
    }

    dynamic_string in_file(g_command_line_params().get_value_as_string_or_empty("", 1));
    dynamic_string out_prefix(g_command_line_params().get_value_as_string_or_empty("", 2));

    printf("Input file: %s\nOutput prefix: %s\n", in_file.get_ptr(), out_prefix.get_ptr());

    cfile_stream in_stream;
    if (!in_stream.open(in_file.get_ptr()))
    {
        vogl_error_printf("Failed opening input file \"%s\"!\n", in_file.get_ptr());
        return EXIT_FAILURE;
    }

    ktx_texture tex;

    data_stream_serializer in_stream_serializer(in_stream);
    if (!tex.read_from_stream(in_stream_serializer))
    {
        vogl_error_printf("Failed parsing input KTX file \"%s\"!\n", in_file.get_ptr());
        return EXIT_FAILURE;
    }

    if (tex.is_compressed())
    {
        //get_ogl_internal_fmt()
        vogl_error_printf("Compressed KTX files are not supported because the pxfmt lib doesn't support compressed formats yet.\n");
        return EXIT_FAILURE;
    }

    pxfmt_sized_format src_pxfmt = validate_format_type_combo(tex.get_ogl_fmt(), tex.get_ogl_type());
    if (src_pxfmt == PXFMT_INVALID)
    {
        vogl_error_printf("Unsupported KTX format/type: 0x%X 0x%X\n", tex.get_ogl_fmt(), tex.get_ogl_type());
        return EXIT_FAILURE;
    }

    // TODO: This is a total work in progress!
    for (uint32_t array_index = 0; array_index < tex.get_array_size(); array_index++)
    {
        for (uint32_t face_index = 0; face_index < tex.get_num_faces(); face_index++)
        {
            for (uint32_t mip_level = 0; mip_level < tex.get_num_mips(); mip_level++)
            {
                uint32_t mip_depth = math::maximum<uint32_t>(1U, tex.get_depth() >> mip_level);

                for (uint32_t zslice_index = 0; zslice_index < mip_depth; zslice_index++)
                {
                    uint32_t mip_width = math::maximum<uint32_t>(1U, tex.get_width() >> mip_level);<commit_msg>ktxtool now prints info from a KTX file's header.<commit_after>// File: ktxtool.cpp

#include <stdlib.h>
#include <stdio.h>

#include "vogl_core.h"
#include "vogl_colorized_console.h"
#include "vogl_command_line_params.h"
#include "vogl_cfile_stream.h"
#include "vogl_ktx_texture.h"
#include "vogl_miniz.h"
#include "vogl_file_utils.h"
#include "vogl_image.h"
#include "vogl_image_utils.h"

#include <GL/gl.h>
#include "pxfmt.h"

using namespace vogl;

//----------------------------------------------------------------------------------------------------------------------
// command line params
//----------------------------------------------------------------------------------------------------------------------
static command_line_param_desc g_command_line_param_descs[] =
    {
        { "help", 0, false, "Display this help" },
        { "?", 0, false, "Display this help" },
    };

//----------------------------------------------------------------------------------------------------------------------
// tool_print_title
//----------------------------------------------------------------------------------------------------------------------
static void tool_print_title()
{
    vogl_printf("ktxtool ");
    if (sizeof(void *) > 4)
        vogl_printf("64-bit ");
    else
        vogl_printf("32-bit ");
#ifdef VOGL_BUILD_DEBUG
    vogl_printf("Debug ");
#else
    vogl_printf("Release ");
#endif
    vogl_printf("Built %s %s\n", __DATE__, __TIME__);
}

//----------------------------------------------------------------------------------------------------------------------
// tool_print_help
//----------------------------------------------------------------------------------------------------------------------
static void tool_print_help()
{
    vogl_printf("Usage: ktxtool [ -option ... ] input_file.ktx output_prefix [ -option ... ]\n");
    vogl_printf("Command line options may begin with single minus \"-\" or double minus \"--\"\n");

    vogl_printf("\nCommand line options:\n");

    dump_command_line_info(VOGL_ARRAY_SIZE(g_command_line_param_descs), g_command_line_param_descs, "--");
}

//----------------------------------------------------------------------------------------------------------------------
// init_command_line_params
//----------------------------------------------------------------------------------------------------------------------
static bool init_command_line_params(int argc, char *argv[])
{
    command_line_params::parse_config parse_cfg;
    parse_cfg.m_single_minus_params = true;
    parse_cfg.m_double_minus_params = true;

    if (!g_command_line_params().parse(get_command_line_params(argc, argv), VOGL_ARRAY_SIZE(g_command_line_param_descs), g_command_line_param_descs, parse_cfg))
    {
        vogl_error_printf("Failed parsing command line parameters!\n");
        return false;
    }

    if (g_command_line_params().get_value_as_bool("help") || g_command_line_params().get_value_as_bool("?"))
    {
        tool_print_help();
        return false;
    }

    return true;
}

//----------------------------------------------------------------------------------------------------------------------
// main
//----------------------------------------------------------------------------------------------------------------------
int main(int argc, char **argv)
{
    // Initialize vogl_core.
    vogl_core_init();

    colorized_console::init();
    colorized_console::set_exception_callback();

    tool_print_title();

    if (!init_command_line_params(argc, argv))
        return EXIT_FAILURE;

    if (g_command_line_params().get_count("") != 3)
    {
        vogl_error_printf("2 parameters required\n");
        return EXIT_FAILURE;
    }

    dynamic_string in_file(g_command_line_params().get_value_as_string_or_empty("", 1));
    dynamic_string out_prefix(g_command_line_params().get_value_as_string_or_empty("", 2));

    printf("Input file: %s\nOutput prefix: %s\n", in_file.get_ptr(), out_prefix.get_ptr());

    cfile_stream in_stream;
    if (!in_stream.open(in_file.get_ptr()))
    {
        vogl_error_printf("Failed opening input file \"%s\"!\n", in_file.get_ptr());
        return EXIT_FAILURE;
    }

    ktx_texture tex;

    data_stream_serializer in_stream_serializer(in_stream);
    if (!tex.read_from_stream(in_stream_serializer))
    {
        vogl_error_printf("Failed parsing input KTX file \"%s\"!\n", in_file.get_ptr());
        return EXIT_FAILURE;
    }

    vogl_printf("KTX header:%s Format=0x%04x, Type=0x%04x,\n\t    "
                "width=%d, height=%d, depth=%d, # mips=%d, # faces=%d, ArraySize=%d\n",
                tex.get_opposite_endianness() ? " OppositeEndianness," : "",
                tex.get_ogl_fmt(), tex.get_ogl_type(),
                tex.get_width(), tex.get_height(), tex.get_depth(),
                tex.get_num_mips(), tex.get_num_faces(), tex.get_array_size());

    if (tex.is_compressed())
    {
        vogl_printf("\t    InternalFormat=0x%04x, BaseInternalFormat=0x%04x,\n\t    "
                    "Compressed texture: BlockDimension=%d, BytesPerBlock=%d\n",
                    tex.get_ogl_internal_fmt(), tex.get_ogl_base_fmt(),
                    tex.get_block_dim(), tex.get_bytes_per_block());

        //get_ogl_internal_fmt()
        vogl_error_printf("Compressed KTX files are not supported because the pxfmt lib doesn't support compressed formats yet.\n");
        return EXIT_FAILURE;
    }

    pxfmt_sized_format src_pxfmt = validate_format_type_combo(tex.get_ogl_fmt(), tex.get_ogl_type());
    if (src_pxfmt == PXFMT_INVALID)
    {
        vogl_error_printf("Unsupported KTX format/type: 0x%X 0x%X\n", tex.get_ogl_fmt(), tex.get_ogl_type());
        return EXIT_FAILURE;
    }

    // TODO: This is a total work in progress!
    for (uint32_t array_index = 0; array_index < tex.get_array_size(); array_index++)
    {
        for (uint32_t face_index = 0; face_index < tex.get_num_faces(); face_index++)
        {
            for (uint32_t mip_level = 0; mip_level < tex.get_num_mips(); mip_level++)
            {
                uint32_t mip_depth = math::maximum<uint32_t>(1U, tex.get_depth() >> mip_level);

                for (uint32_t zslice_index = 0; zslice_index < mip_depth; zslice_index++)
                {
                    uint32_t mip_width = math::maximum<uint32_t>(1U, tex.get_width() >> mip_level);
{'fraction_non_alphanumeric': 0.30485355648535567, 'fraction_numerical': 0.0068619246861924684, 'mean_word_length': 1.6185363716038563, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 23, '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': '321218', 'n_tokens_mistral': 3579, 'n_tokens_neox': 3399, 'n_words': 598}