Get a better cell size for the rendering of the image.
This commit is contained in:
parent
6f0f3f01d9
commit
a4926bedcb
1 changed files with 12 additions and 12 deletions
|
@ -81,7 +81,7 @@ int main(int argc, char *argv[]) {
|
||||||
// divide the image into cells
|
// divide the image into cells
|
||||||
auto size = image.getSize();
|
auto size = image.getSize();
|
||||||
|
|
||||||
const int cell = 3;
|
const Point cell = {4, 6};
|
||||||
|
|
||||||
// create a grid panel to hold the cells
|
// create a grid panel to hold the cells
|
||||||
Panel panel(0, 0, 0, 0, true);
|
Panel panel(0, 0, 0, 0, true);
|
||||||
|
@ -90,16 +90,16 @@ int main(int argc, char *argv[]) {
|
||||||
RGBColor avg{0,0,0};
|
RGBColor avg{0,0,0};
|
||||||
|
|
||||||
typedef vector<RGBColor> ColorRow;
|
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
|
// LOL, so bad but just the start
|
||||||
for(unsigned int i = 0; i < size.x / cell; i++) {
|
for(unsigned int i = 0; i < size.x / cell.x; i++) {
|
||||||
for(unsigned int j = 0; j < size.y / cell; j++) {
|
for(unsigned int j = 0; j < size.y / cell.y; j++) {
|
||||||
|
|
||||||
// sum the cell
|
// sum the cell
|
||||||
for(unsigned int x = 0; x < cell ; x++) {
|
for(unsigned int x = 0; x < cell.x ; x++) {
|
||||||
for(unsigned int y = 0; y < cell ; y++) {
|
for(unsigned int y = 0; y < cell.y ; y++) {
|
||||||
auto pixel = image.getPixel((i*cell) + x, (j * cell) + y);
|
auto pixel = image.getPixel((i*cell.x) + x, (j * cell.y) + y);
|
||||||
|
|
||||||
avg.r += pixel.r;
|
avg.r += pixel.r;
|
||||||
avg.g += pixel.g;
|
avg.g += pixel.g;
|
||||||
|
@ -108,8 +108,8 @@ int main(int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// average it for the cell size
|
// average it for the cell size
|
||||||
RGBColor color = {avg.r / (cell * cell),
|
RGBColor color = {avg.r / int(cell.x * cell.y),
|
||||||
avg.g / (cell * cell), avg.b / (cell * cell)};
|
avg.g / int(cell.x * cell.y), avg.b / int(cell.x * cell.y)};
|
||||||
|
|
||||||
// add it
|
// add it
|
||||||
colors[i][j] = color;
|
colors[i][j] = color;
|
||||||
|
@ -124,10 +124,10 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
SFMLRender renderer;
|
SFMLRender renderer;
|
||||||
|
|
||||||
if(renderer.resize_grid(10, panel)) {
|
renderer.resize_grid(26, panel);
|
||||||
drawing = Canvas(panel.width * 2, panel.height * 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
drawing = Canvas(panel.width * 2, panel.height * 4);
|
||||||
|
panel.resize(240,240);
|
||||||
|
|
||||||
panel.set_renderer(Renderer([&]{
|
panel.set_renderer(Renderer([&]{
|
||||||
for(size_t x = 0; x < colors.size(); x++) {
|
for(size_t x = 0; x < colors.size(); x++) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue