From a4926bedcb395b02abfbd33183c798579537ef4e Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Thu, 21 Nov 2024 16:43:39 -0500 Subject: [PATCH] Get a better cell size for the rendering of the image. --- scratchpad/img2ansi.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/scratchpad/img2ansi.cpp b/scratchpad/img2ansi.cpp index e102557..8e9a00c 100644 --- a/scratchpad/img2ansi.cpp +++ b/scratchpad/img2ansi.cpp @@ -81,7 +81,7 @@ int main(int argc, char *argv[]) { // divide the image into cells auto size = image.getSize(); - const int cell = 3; + const Point cell = {4, 6}; // create a grid panel to hold the cells Panel panel(0, 0, 0, 0, true); @@ -90,16 +90,16 @@ int main(int argc, char *argv[]) { RGBColor avg{0,0,0}; typedef vector ColorRow; - vector colors(size.x / cell, ColorRow(size.y / cell)); + vector colors(size.x / cell.x, ColorRow(size.y / cell.y)); // LOL, so bad but just the start - for(unsigned int i = 0; i < size.x / cell; i++) { - for(unsigned int j = 0; j < size.y / cell; j++) { + for(unsigned int i = 0; i < size.x / cell.x; i++) { + for(unsigned int j = 0; j < size.y / cell.y; j++) { // sum the cell - for(unsigned int x = 0; x < cell ; x++) { - for(unsigned int y = 0; y < cell ; y++) { - auto pixel = image.getPixel((i*cell) + x, (j * cell) + y); + for(unsigned int x = 0; x < cell.x ; x++) { + for(unsigned int y = 0; y < cell.y ; y++) { + auto pixel = image.getPixel((i*cell.x) + x, (j * cell.y) + y); avg.r += pixel.r; avg.g += pixel.g; @@ -108,8 +108,8 @@ int main(int argc, char *argv[]) { } // average it for the cell size - RGBColor color = {avg.r / (cell * cell), - avg.g / (cell * cell), avg.b / (cell * cell)}; + RGBColor color = {avg.r / int(cell.x * cell.y), + avg.g / int(cell.x * cell.y), avg.b / int(cell.x * cell.y)}; // add it colors[i][j] = color; @@ -124,10 +124,10 @@ int main(int argc, char *argv[]) { SFMLRender renderer; - if(renderer.resize_grid(10, panel)) { - drawing = Canvas(panel.width * 2, panel.height * 4); - } + renderer.resize_grid(26, panel); + drawing = Canvas(panel.width * 2, panel.height * 4); + panel.resize(240,240); panel.set_renderer(Renderer([&]{ for(size_t x = 0; x < colors.size(); x++) {