40 std::vector<int> cache(M, 0);
41 std::stack<std::pair<int, int> > stack;
42 for (
int x = N - 1; x >= 0; -- x) {
43 updateCache(pixels, cache, x, N);
45 for (
int y = 0; y < M; ++ y) {
46 if (cache[y] > width) {
47 stack.push(std::make_pair(y, width));
49 }
else if (cache[y] < width) {
52 std::tie(y0, w0) = stack.top();
54 if (width * (y - y0) > bestArea) {
55 bestLL.x_m = x; bestLL.y_m = y0;
56 bestUR.
x_m = x + width; bestUR.
y_m = y;
57 bestArea = width * (y - y0);
60 }
while (!stack.empty() && cache[y] < width);
63 stack.push(std::make_pair(y0, width));
70 std::tie(y0, w0) = stack.top();
72 if (width * (N - y0) > bestArea) {
73 bestLL.x_m = x; bestLL.y_m = y0;
74 bestUR.
x_m = x + width; bestUR.
y_m = N;
75 bestArea = width * (N - y0);
80 return std::make_pair(bestLL, bestUR);
87 std::vector<IntPixel_t> rectangles;
93 if (area > maxArea) maxArea = area;
98 rectangles.push_back(pix);
100 for (
int y = pix.first.y_m; y < pix.second.y_m; ++ y) {
101 int idx = y * N + pix.first.x_m;
102 for (
int x = pix.first.x_m; x < pix.second.x_m; ++ x, ++ idx) {
108 for (
int y = 0; y < M; ++ y) {
109 for (
int x = 0; x < N; ++ x, ++idx) {
122 Mask *pixmap =
static_cast<Mask*
>(fun);
125 std::string filename = arguments.
get(0);
126 if (filename[0] ==
'\'' && filename.back() ==
'\'') {
127 filename = filename.substr(1, filename.length() - 2);
130 if (!std::filesystem::exists(filename)) {
131 ERRORMSG(
"file '" << filename <<
"' doesn't exists" <<
endl);
144 }
catch (std::runtime_error &e) {
145 std::cout << e.what() << std::endl;
149 if (pixel_width < 0.0) {
150 std::cout <<
"Mask: a negative width provided '"
151 << arguments.
get(0) <<
" = " << pixel_width * width <<
"'"
156 if (pixel_height < 0.0) {
157 std::cout <<
"Mask: a negative height provided '"
158 << arguments.
get(1) <<
" = " << pixel_height * height <<
"'"
172 double midX = 0.5 * (ur.
x_m + ll.
x_m);
173 double midY = 0.5 * (ur.
y_m + ll.
y_m);
175 Vector_t(0, 1, (midY - 0.5 * height) * pixel_height));
178 pixmap->
pixels_m.back().computeBoundingBox();