107 int* old_grid = grid_;
114 for (
int oldy = 0; oldy < old_height; ++oldy) {
115 FCOORD line_pos(old_bleft.x(), old_bleft.y() +
gridsize() * oldy);
116 line_pos.
rotate(rotation);
117 for (
int oldx = 0; oldx < old_width; ++oldx, line_pos += x_step, ++oldi) {
119 GridCoords(static_cast<int>(line_pos.x() + 0.5),
120 static_cast<int>(line_pos.y() + 0.5),
122 grid_[grid_y *
gridwidth() + grid_x] = old_grid[oldi];
137 for (
int yoffset = -1; yoffset <= 1; ++yoffset) {
138 for (
int xoffset = -1; xoffset <= 1; ++xoffset) {
139 int grid_x = x + xoffset;
140 int grid_y = y + yoffset;
146 sumgrid->SetGridCell(x, y, cell_count);
155 int min_x, min_y, max_x, max_y;
159 for (
int y = min_y; y <= max_y; ++y) {
160 for (
int x = min_x; x <= max_x; ++x) {
162 if (value > threshold) {
166 total_area += cell_box.
area();
170 return total_area * 2 > rect.
area();
175 int min_x, min_y, max_x, max_y;
178 for (
int y = min_y; y <= max_y; ++y) {
179 for (
int x = min_x; x <= max_x; ++x) {
199 pixRasterop(pix, x * cellsize,
tright().y() - ((y + 1) * cellsize),
200 cellsize, cellsize, PIX_SET,
nullptr, 0, 0);
208 static Pix* GridReducedPix(
const TBOX& box,
int gridsize,
209 ICOORD bleft,
int* left,
int* bottom) {
211 int grid_left = (box.
left() - bleft.
x()) / gridsize - 1;
212 int grid_bottom = (box.
bottom() - bleft.
y()) / gridsize - 1;
213 int grid_right = (box.
right() - bleft.
x()) / gridsize + 1;
214 int grid_top = (box.
top() - bleft.
y()) / gridsize + 1;
216 *bottom = grid_bottom;
217 return pixCreate(grid_right - grid_left + 1,
218 grid_top - grid_bottom + 1,
229 ICOORD bleft,
int* left,
int* bottom) {
231 Pix* pix = GridReducedPix(box, gridsize, bleft, left, bottom);
232 int wpl = pixGetWpl(pix);
233 l_uint32* data = pixGetData(pix);
236 for (
int i = 0; i < length; ++i) {
237 int grid_x = (pos.
x() - bleft.
x()) / gridsize - *left;
238 int grid_y = (pos.
y() - bleft.
y()) / gridsize - *bottom;
239 SET_DATA_BIT(data + grid_y * wpl, grid_x);
240 pos += outline->
step(i);
244 #if 0 // Example code shows how to use TraceOutlineOnReducedPix.
245 C_OUTLINE_IT ol_it(blob->cblob()->out_list());
246 int grid_left, grid_bottom;
248 &grid_left, &grid_bottom);
249 grid->InsertPixPtBBox(grid_left, grid_bottom, pix, blob);
255 ICOORD bleft,
int* left,
int* bottom) {
257 Pix* pix = GridReducedPix(box, gridsize, bleft, left, bottom);
258 int wpl = pixGetWpl(pix);
259 l_uint32* data = pixGetData(pix);
261 for (it.mark_cycle_pt(); !it.cycled_list();) {
264 ICOORD next_pos = *it.data();
265 ICOORD line_vector = next_pos - pos;
267 ICOORD major_step, minor_step;
268 line_vector.
setup_render(&major_step, &minor_step, &major, &minor);
269 int accumulator = major / 2;
270 while (pos != next_pos) {
271 int grid_x = (pos.x() - bleft.
x()) / gridsize - *left;
272 int grid_y = (pos.y() - bleft.
y()) / gridsize - *bottom;
273 SET_DATA_BIT(data + grid_y * wpl, grid_x);
275 accumulator += minor;
276 if (accumulator >= major) {
277 accumulator -= major;