operations apply over images
parent
c4b2de9503
commit
dc7bd2fd22
Binary file not shown.
|
@ -202,3 +202,11 @@
|
|||
26737 26901 1705257472228626060 libraries/BLT-With-Graphics-Template/libraries/freetype-2.13.2/libfreetype.a 1ef1507fdc5a3960
|
||||
26901 27054 1705257472380619772 libraries/BLT-With-Graphics-Template/libBLT_WITH_GRAPHICS.a 2582d8919b3ccd7b
|
||||
27054 27191 1705257472520613980 gp_image_test 627b40e9bcf815e3
|
||||
9 49 1705257551849331804 libraries/BLT-With-Graphics-Template/libraries/openal-soft/version_witness.txt 6325405b7e3e96f7
|
||||
9 49 1705257551849331804 libraries/BLT-With-Graphics-Template/libraries/openal-soft/version.h 6325405b7e3e96f7
|
||||
9 49 1705257551849331804 /home/brett/Documents/code/c++/gp_image_test/cmake-build-release/libraries/BLT-With-Graphics-Template/libraries/openal-soft/version_witness.txt 6325405b7e3e96f7
|
||||
9 49 1705257551849331804 /home/brett/Documents/code/c++/gp_image_test/cmake-build-release/libraries/BLT-With-Graphics-Template/libraries/openal-soft/version.h 6325405b7e3e96f7
|
||||
9 2237 1705433087834197608 libraries/BLT-With-Graphics-Template/libraries/BLT/CMakeFiles/BLT.dir/src/blt/std/system.cpp.o 19facd5153bbeb65
|
||||
2237 2427 1705433088022195202 libraries/BLT-With-Graphics-Template/libraries/BLT/libBLT.a 5e3491f3bb42050d
|
||||
9 3115 1705433088714186351 CMakeFiles/gp_image_test.dir/src/main.cpp.o d2247c8eaef04c80
|
||||
3116 3265 1705433088862184459 gp_image_test 627b40e9bcf815e3
|
||||
|
|
Binary file not shown.
|
@ -1,3 +1,3 @@
|
|||
Start testing: Jan 15 14:34 EST
|
||||
Start testing: Jan 16 14:24 EST
|
||||
----------------------------------------------------------
|
||||
End testing: Jan 15 14:34 EST
|
||||
End testing: Jan 16 14:24 EST
|
||||
|
|
Binary file not shown.
|
@ -0,0 +1,121 @@
|
|||
/*
|
||||
* <Short Description>
|
||||
* Copyright (C) 2024 Brett Terpstra
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GP_IMAGE_TEST_IMAGE_H
|
||||
#define GP_IMAGE_TEST_IMAGE_H
|
||||
|
||||
#define NO_BLT_NAMESPACE_ON_TYPES
|
||||
|
||||
#include <blt/std/types.h>
|
||||
#include <array>
|
||||
#include <optional>
|
||||
#include "blt/std/assert.h"
|
||||
|
||||
inline constexpr i32 width = 1024, height = 1024;
|
||||
|
||||
class image
|
||||
{
|
||||
private:
|
||||
std::array<u8, width * height * 4> data;
|
||||
public:
|
||||
image() = default;
|
||||
|
||||
u8 get(i32 x, i32 y)
|
||||
{
|
||||
return data[y * height + x];
|
||||
}
|
||||
|
||||
void set(u8 c, i32 x, i32 y)
|
||||
{
|
||||
data[y * height + x] = c;
|
||||
}
|
||||
};
|
||||
|
||||
enum class function_t
|
||||
{
|
||||
// FUNC // inputs
|
||||
ADD, // 2
|
||||
SUB, // 2
|
||||
MUL, // 2
|
||||
DIV, // 2
|
||||
EXP, // 2
|
||||
|
||||
LOG, // 1
|
||||
SQRT, // 1
|
||||
QUAD, // 1
|
||||
|
||||
RANDOM, // 0
|
||||
NOISE, // 0
|
||||
COLOR, // 0
|
||||
SCALAR // 0
|
||||
};
|
||||
|
||||
inline i32 inputs(function_t op)
|
||||
{
|
||||
// don't like this but it'll get compiled out
|
||||
// and we get warnings when new enum is added
|
||||
switch (op)
|
||||
{
|
||||
case function_t::ADD:
|
||||
case function_t::SUB:
|
||||
case function_t::MUL:
|
||||
case function_t::DIV:
|
||||
case function_t::EXP:
|
||||
return 2;
|
||||
case function_t::LOG:
|
||||
case function_t::SQRT:
|
||||
case function_t::QUAD:
|
||||
return 1;
|
||||
case function_t::RANDOM:
|
||||
case function_t::NOISE:
|
||||
case function_t::COLOR:
|
||||
case function_t::SCALAR:
|
||||
return 0;
|
||||
}
|
||||
BLT_THROW(std::runtime_error("If you are seeing this the universe has broken. Enjoy whatever hellhole is left"));
|
||||
}
|
||||
|
||||
struct op_con
|
||||
{
|
||||
function_t op;
|
||||
std::optional<image*> i1, i2;
|
||||
|
||||
op_con(function_t op, const std::optional<image*>& i1, const std::optional<image*>& i2): op(op), i1(i1), i2(i2)
|
||||
{}
|
||||
|
||||
[[nodiscard]] bool has_both() const
|
||||
{
|
||||
return i1.has_value() && i2.has_value();
|
||||
}
|
||||
|
||||
[[nodiscard]] bool has_one() const
|
||||
{
|
||||
return i1.has_value() || i2.has_value();
|
||||
}
|
||||
|
||||
[[nodiscard]] image* getOne()
|
||||
{
|
||||
if (i1)
|
||||
return i1.value();
|
||||
if (i2)
|
||||
return i2.value();
|
||||
BLT_THROW(std::runtime_error("Unable to get when one is missing! You have an error in your GA!"));
|
||||
}
|
||||
};
|
||||
|
||||
#endif //GP_IMAGE_TEST_IMAGE_H
|
145
src/main.cpp
145
src/main.cpp
|
@ -3,9 +3,12 @@
|
|||
#include <blt/gfx/window.h>
|
||||
#include <blt/gfx/state.h>
|
||||
#include <blt/gfx/stb/stb_image.h>
|
||||
#include <blt/gfx/stb/stb_perlin.h>
|
||||
#include <blt/std/hashmap.h>
|
||||
#include <image.h>
|
||||
#include "blt/gfx/renderer/resource_manager.h"
|
||||
#include "blt/gfx/renderer/batch_2d_renderer.h"
|
||||
#include "blt/std/assert.h"
|
||||
#include <variant>
|
||||
#include <random>
|
||||
|
||||
|
@ -15,29 +18,118 @@ blt::gfx::batch_renderer_2d renderer_2d(resources);
|
|||
|
||||
struct node;
|
||||
|
||||
blt::area_allocator<node, 32000> allocator;
|
||||
blt::area_allocator<node, 32000> node_allocator;
|
||||
blt::area_allocator<image, 32000> img_allocator;
|
||||
|
||||
std::variant<float, blt::vec3f> input_t;
|
||||
|
||||
enum class function_t
|
||||
node* createNode()
|
||||
{
|
||||
// FUNC // inputs
|
||||
ADD, // 2
|
||||
SUB, // 2
|
||||
MUL, // 2
|
||||
DIV, // 2
|
||||
|
||||
LOG, // 1
|
||||
EXP, // 1
|
||||
SQRT, // 1
|
||||
POW, // 1
|
||||
QUAD, // 1
|
||||
|
||||
RANDOM, // 0
|
||||
NOISE, // 0
|
||||
COLOR, // 0
|
||||
SCALAR // 0
|
||||
};
|
||||
auto* n = node_allocator.allocate(1);
|
||||
node_allocator.construct(n);
|
||||
return n;
|
||||
}
|
||||
|
||||
image* createImage()
|
||||
{
|
||||
auto* i = img_allocator.allocate(1);
|
||||
img_allocator.construct(i);
|
||||
return i;
|
||||
}
|
||||
|
||||
void destroyNode(node* n)
|
||||
{
|
||||
node_allocator.destroy(n);
|
||||
node_allocator.deallocate(n, 1);
|
||||
}
|
||||
|
||||
void destroyImage(image* img)
|
||||
{
|
||||
img_allocator.destroy(img);
|
||||
img_allocator.deallocate(img, 1);
|
||||
}
|
||||
|
||||
image* apply_operator(op_con operation)
|
||||
{
|
||||
auto* ret = createImage();
|
||||
for (i32 y = 0; y < height; y++)
|
||||
{
|
||||
for (i32 x = 0; x < width; x++)
|
||||
{
|
||||
switch (operation.op)
|
||||
{
|
||||
case function_t::ADD:
|
||||
{
|
||||
BLT_ASSERT(operation.has_both());
|
||||
ret->set((operation.i1.value()->get(x, y) + operation.i2.value()->get(x, y)) % std::numeric_limits<u8>::max(), x, y);
|
||||
break;
|
||||
}
|
||||
case function_t::SUB:
|
||||
{
|
||||
BLT_ASSERT(operation.has_both());
|
||||
ret->set((operation.i1.value()->get(x, y) - operation.i2.value()->get(x, y)) % std::numeric_limits<u8>::max(), x, y);
|
||||
break;
|
||||
}
|
||||
case function_t::MUL:
|
||||
{
|
||||
BLT_ASSERT(operation.has_both());
|
||||
ret->set((operation.i1.value()->get(x, y) * operation.i2.value()->get(x, y)) % std::numeric_limits<u8>::max(), x, y);
|
||||
break;
|
||||
}
|
||||
case function_t::DIV:
|
||||
{
|
||||
BLT_ASSERT(operation.has_both());
|
||||
auto den = operation.i2.value()->get(x, y);
|
||||
if (den == 0)
|
||||
ret->set(0, x, y);
|
||||
else
|
||||
ret->set((operation.i1.value()->get(x, y) / den) % std::numeric_limits<u8>::max(), x, y);
|
||||
break;
|
||||
}
|
||||
case function_t::EXP:
|
||||
{
|
||||
BLT_ASSERT(operation.has_both());
|
||||
ret->set(static_cast<u8>(std::pow(operation.i1.value()->get(x, y), operation.i2.value()->get(x, y))), x, y);
|
||||
break;
|
||||
}
|
||||
case function_t::LOG:
|
||||
{
|
||||
BLT_ASSERT(operation.has_one());
|
||||
ret->set(static_cast<u8>(std::log(static_cast<double>(operation.getOne()->get(x, y)))), x, y);
|
||||
break;
|
||||
}
|
||||
case function_t::SQRT:
|
||||
{
|
||||
BLT_ASSERT(operation.has_one());
|
||||
ret->set(static_cast<u8>(std::sqrt(static_cast<double>(operation.getOne()->get(x, y)))), x, y);
|
||||
break;
|
||||
}
|
||||
case function_t::QUAD:
|
||||
{
|
||||
BLT_ASSERT(operation.has_one());
|
||||
auto v = operation.getOne()->get(x, y);
|
||||
ret->set(static_cast<u8>(v * v), x, y);
|
||||
break;
|
||||
}
|
||||
case function_t::RANDOM:
|
||||
{
|
||||
|
||||
break;
|
||||
}
|
||||
case function_t::NOISE:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case function_t::COLOR:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case function_t::SCALAR:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static constexpr int OPERATOR_COUNT = 13;
|
||||
|
||||
|
@ -45,7 +137,7 @@ class tree;
|
|||
|
||||
struct node
|
||||
{
|
||||
friend tree;
|
||||
friend tree;
|
||||
private:
|
||||
node* left;
|
||||
node* right;
|
||||
|
@ -55,8 +147,7 @@ struct node
|
|||
|
||||
static node* construct_random()
|
||||
{
|
||||
node* n = allocator.allocate(1);
|
||||
allocator.construct(n);
|
||||
node* n = createNode();
|
||||
|
||||
std::random_device dev;
|
||||
std::mt19937_64 engine{dev()};
|
||||
|
@ -72,10 +163,8 @@ struct node
|
|||
|
||||
~node()
|
||||
{
|
||||
allocator.destroy(left);
|
||||
allocator.deallocate(left, 1);
|
||||
allocator.destroy(right);
|
||||
allocator.deallocate(right, 1);
|
||||
destroyNode(left);
|
||||
destroyNode(right);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue