Get a better cell size for the rendering of the image.

main
Zed A. Shaw 2 days ago
parent 6f0f3f01d9
commit a4926bedcb
  1. 24
      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<RGBColor> ColorRow;
vector<ColorRow> colors(size.x / cell, ColorRow(size.y / cell));
vector<ColorRow> 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++) {

Loading…
Cancel
Save