#include "./lib/lodepng.h" #include "imgToArr.cpp" #include #include #include #include //g++ ./primis.cpp ./lib/lodepng.cpp -I./ -ansi -pedantic -Wall -Wextra -O3 -std=c++14 -o clbl using namespace std; typedef char byte; int avg(pixel pix) { int r = pix.r, g = pix.g, b = pix.b; return (r+g+b)/3; } struct coord{ int x; int y; }; vector getPreCoords(coord size, coord currentCoord){ vector outCoords; for(int x = currentCoord.x; x <= currentCoord.x+1; ++x) for(int y = currentCoord.y; y <= currentCoord.y+1; ++y) if(x < size.x && y < size.y) outCoords.push_back({x, y}); return outCoords; } struct color { unsigned r, g, b; static color avg(vector); static color fromPixel(pixel pix); color operator+(color other); color operator/(int div); }; color color::operator+(color other) { return {other.r+r, other.g+g, other.b+b}; } color color::fromPixel(pixel pix) { return {pix.r, pix.g, pix.b}; } color color::operator/(int div) { return {r/div, g/div, b/div}; } color color::avg(vector colors) { color result; unsigned count = 0; for(auto color:colors) { result = result + color; count++; } result = result/count; return result; } /// color findAvgCol(Frame *img, vector coords) { vector colors; for(auto coord:coords) { pixel *temp = img->getPixelAt(coord.x, coord.y); color temppix = color::fromPixel(*temp); colors.push_back(temppix); } return color::avg(colors); } struct node { //координаты указывающие на точки прошлого слоя vector preCoords; //средний цвет юнита color avgCol = {0, 0, 0}; }; struct Layer { vector> layer; int width, height; int deep = 0; Layer *past = nullptr; static Layer fromFrame(Frame *); static Layer fromLayer(Layer *); vector getAllUnder(coord, vector); }; vector Layer::getAllUnder(coord point, vector all) { int curentDeep = deep; cout<<"curentDeep: "< pointerCoords = layer[point.x][point.y].preCoords; while(curentDeep > 0){ cout<<"usize: "< newCoords; for(coord one:pointerCoords) { vector buffer = currentLayer.layer[one.x][one.y].preCoords; newCoords.insert(newCoords.end(), buffer.begin(), buffer.end()); } pointerCoords = newCoords; } return pointerCoords; } color findAvgColL(Layer *img, vector coords) { vector colors; for(auto coord:coords) { color temp = img->layer[coord.x][coord.y].avgCol; colors.push_back(temp); } return color::avg(colors); } //// Layer Layer::fromFrame(Frame *main) { int width = main->width/2 + main->width%2; int height = main->height/2 + main->height%2; int pastWidth = main->width; int pastHeight = main->height; vector> layer; layer.resize(width+1, vector(height+1)); for(int x = 0; x < width; x++) for(int y = 0; y < height; y++) { auto pastCoords = getPreCoords({pastWidth, pastHeight}, {x*2, y*2}); if(pastCoords.size()>4) cout<<"AAAAAAAAAAAAAAAAAAAAAA"<deep + 1; int width = past->width/2 + past->width%2; int height = past->height/2 + past->height%2; int pastWidth = past->width; int pastHeight = past->height; vector> layer; layer.resize(width+1, vector(height+1)); for(int x = 0; x < width; x++) for(int y = 0; y < height; y++) { auto pastCoords = getPreCoords({pastWidth, pastHeight}, {x*2, y*2}); if(pastCoords.size()>4) cout<<"AAAAAAAAAAAAAAAAAAAAAA"<toPixelArray(); auto base = Layer::fromFrame(image); //collecting pyramid vector pyramid; pyramid.push_back(Layer::fromLayer(&base)); int lastIndex; do { lastIndex = pyramid.size()-1; pyramid.push_back(Layer::fromLayer(&pyramid[lastIndex])); } while ( pyramid[lastIndex].width > 2 || pyramid[lastIndex].height > 2 ); //add layers until it's expression is not equal to false /// cout << "last w: " << pyramid[lastIndex].width << endl; cout << "last h: " << pyramid[lastIndex].height << endl; vector points = pyramid[lastIndex].getAllUnder({0, 0}, pyramid); cout<< "size : "<toPixelArray(); auto col = pyramid[lastIndex].layer[0][0].avgCol; for(coord pix:points) { delete outImage->arr[pix.x][pix.y]; outImage->arr[pix.x][pix.y] = new pixel{col.r,col.g,col.b,255}; } outImage->save(out); }