46 std::vector<int> cache(M, 0);
47 std::stack<std::pair<int, int> > stack;
48 for (
int x = N - 1; x >= 0; -- x) {
49 updateCache(pixels, cache, x, N);
51 for (
int y = 0; y < M; ++ y) {
52 if (cache[y] > width) {
53 stack.push(std::make_pair(y, width));
55 }
else if (cache[y] < width) {
58 std::tie(y0, w0) = stack.top();
60 if (width * (y - y0) > bestArea) {
61 bestLL.x_m = x; bestLL.y_m = y0;
62 bestUR.
x_m = x + width; bestUR.
y_m = y;
63 bestArea = width * (y - y0);
66 }
while (!stack.empty() && cache[y] < width);
69 stack.push(std::make_pair(y0, width));
76 std::tie(y0, w0) = stack.top();
78 if (width * (N - y0) > bestArea) {
79 bestLL.x_m = x; bestLL.y_m = y0;
80 bestUR.
x_m = x + width; bestUR.
y_m = N;
81 bestArea = width * (N - y0);
86 return std::make_pair(bestLL, bestUR);
93 std::vector<IntPixel_t> rectangles;
99 if (area > maxArea) maxArea = area;
104 rectangles.push_back(pix);
106 for (
int y = pix.first.y_m; y < pix.second.y_m; ++ y) {
107 int idx = y * N + pix.first.x_m;
108 for (
int x = pix.first.x_m; x < pix.second.x_m; ++ x, ++ idx) {
114 for (
int y = 0; y < M; ++ y) {
115 for (
int x = 0; x < N; ++ x, ++idx) {
128 Mask *pixmap =
static_cast<Mask*
>(fun);
131 std::string filename = arguments.
get(0);
132 if (filename[0] ==
'\'' && filename.back() ==
'\'') {
133 filename = filename.substr(1, filename.length() - 2);
136 if (!std::filesystem::exists(filename)) {
137 ERRORMSG(
"file '" << filename <<
"' doesn't exists" <<
endl);
150 }
catch (std::runtime_error &e) {
151 std::cout << e.what() << std::endl;
155 if (pixel_width < 0.0) {
156 std::cout <<
"Mask: a negative width provided '"
157 << arguments.
get(0) <<
" = " << pixel_width * width <<
"'"
162 if (pixel_height < 0.0) {
163 std::cout <<
"Mask: a negative height provided '"
164 << arguments.
get(1) <<
" = " << pixel_height * height <<
"'"
178 double midX = 0.5 * (ur.
x_m + ll.
x_m);
179 double midY = 0.5 * (ur.
y_m + ll.
y_m);
181 Vector_t({0, 1, (midY - 0.5 * height) * pixel_height}));
184 pixmap->
pixels_m.back().computeBoundingBox();