From cf579eda46fd9ce0183225e7ed5051186803944a Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Mon, 15 Jul 2024 21:22:50 -0400 Subject: [PATCH] floats suck --- CMakeLists.txt | 2 +- lib/blt-gp | 2 +- lib/blt-graphics | 2 +- src/main.cpp | 51 +++++++++++++++++++++++++----------------------- 4 files changed, 30 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 84f4901..8a12aa9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.25) -project(image-gp-6 VERSION 0.0.8) +project(image-gp-6 VERSION 0.0.9) include(FetchContent) diff --git a/lib/blt-gp b/lib/blt-gp index 37e8856..9ff8616 160000 --- a/lib/blt-gp +++ b/lib/blt-gp @@ -1 +1 @@ -Subproject commit 37e885634800331ce68de3ae6dea9ac5d6202d53 +Subproject commit 9ff86161bb7caddbd6ac942c4373465a8af573aa diff --git a/lib/blt-graphics b/lib/blt-graphics index 8fd5222..4e34161 160000 --- a/lib/blt-graphics +++ b/lib/blt-graphics @@ -1 +1 @@ -Subproject commit 8fd52222939b9e58da8511d9000bb1cf12e4de71 +Subproject commit 4e34161bcb3f7e12879c519a2fda10f223bdea63 diff --git a/src/main.cpp b/src/main.cpp index fc07d42..57a2469 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -53,25 +53,47 @@ struct context float x, y; }; +inline context get_ctx(blt::size_t i) +{ + context ctx{}; + ctx.y = std::floor(static_cast(i) / static_cast(IMAGE_SIZE * CHANNELS)); + ctx.x = static_cast(i) - (ctx.y * IMAGE_SIZE * CHANNELS); + return ctx; +} + +inline context get_pop_ctx(blt::size_t i) +{ + auto const sq = static_cast(std::sqrt(POP_SIZE)); + context ctx{}; + ctx.y = std::floor(static_cast(i) / static_cast(sq)); + ctx.x = static_cast(i) - (ctx.y * sq); + return ctx; +} + struct full_image_t { - blt::u8 rgb_data[DATA_SIZE * CHANNELS]; + float rgb_data[DATA_SIZE * CHANNELS]; full_image_t() = default; void load(const std::string& path) { int width, height, channels; - auto data = stbi_load(path.c_str(), &width, &height, &channels, CHANNELS); + auto data = stbi_loadf(path.c_str(), &width, &height, &channels, CHANNELS); - stbir_resize_uint8_linear(data, width, height, 0, rgb_data, IMAGE_SIZE, IMAGE_SIZE, 0, static_cast(CHANNELS)); + stbir_resize_float_linear(data, width, height, 0, rgb_data, IMAGE_SIZE, IMAGE_SIZE, 0, static_cast(CHANNELS)); stbi_image_free(data); } void save(const std::string& str) { - stbi_write_png(str.c_str(), IMAGE_SIZE, IMAGE_SIZE, CHANNELS, rgb_data, 0); + //stbi_write_png(str.c_str(), IMAGE_SIZE, IMAGE_SIZE, CHANNELS, rgb_data, 0); + } + + friend std::ostream& operator<<(std::ostream& str, const full_image_t&) + { + return str; } }; @@ -186,7 +208,7 @@ static blt::gp::operation_t perlin_terminal([](const context& context) { for (unsigned char& i : img.rgb_data) i = static_cast(program.get_random().get_u32(0, 256.0)); return img; - return ; + return; }, "perlin_term"); static blt::gp::operation_t op_x([](const context& context) { return context.x; @@ -195,23 +217,6 @@ static blt::gp::operation_t op_y([](const context& context) { return context.y; }, "y"); -inline context get_ctx(blt::size_t i) -{ - context ctx{}; - ctx.y = std::floor(static_cast(i) / static_cast(IMAGE_SIZE)); - ctx.x = static_cast(i) - (ctx.y * IMAGE_SIZE); - return ctx; -} - -inline context get_pop_ctx(blt::size_t i) -{ - auto const sq = static_cast(std::sqrt(POP_SIZE)); - context ctx{}; - ctx.y = std::floor(static_cast(i) / static_cast(sq)); - ctx.x = static_cast(i) - (ctx.y * sq); - return ctx; -} - constexpr auto create_fitness_function() { return [](blt::gp::tree_t& current_tree, blt::gp::fitness_t& fitness, blt::size_t index) { @@ -277,8 +282,6 @@ void init(const blt::gfx::window_data&) type_system.register_type(); blt::gp::operator_builder builder{type_system}; - builder.add_operator(perlin); - builder.add_operator(perlin_bumpy); builder.add_operator(perlin_terminal); builder.add_operator(add);