107 int *old_grid = grid_;
114 for (
int oldy = 0; oldy < old_height; ++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),
static_cast<int>(line_pos.
y() + 0.5),
121 grid_[grid_y *
gridwidth() + grid_x] = old_grid[oldi];
136 for (
int yoffset = -1; yoffset <= 1; ++yoffset) {
137 for (
int xoffset = -1; xoffset <= 1; ++xoffset) {
138 int grid_x =
x + xoffset;
139 int grid_y =
y + yoffset;
145 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) {
165 total_area += cell_box.
area();
169 return total_area * 2 > rect.
area();
174 int min_x, min_y, max_x, max_y;
177 for (
int y = min_y;
y <= max_y; ++
y) {
178 for (
int x = min_x;
x <= max_x; ++
x) {
198 pixRasterop(pix,
x * cellsize,
tright().
y() - ((
y + 1) * cellsize), cellsize, cellsize,
199 PIX_SET,
nullptr, 0, 0);
207static Image GridReducedPix(
const TBOX &box,
int gridsize,
ICOORD bleft,
int *left,
int *bottom) {
209 int grid_left = (box.
left() - bleft.
x()) / gridsize - 1;
210 int grid_bottom = (box.
bottom() - bleft.
y()) / gridsize - 1;
211 int grid_right = (box.
right() - bleft.
x()) / gridsize + 1;
212 int grid_top = (box.
top() - bleft.
y()) / gridsize + 1;
214 *bottom = grid_bottom;
215 return pixCreate(grid_right - grid_left + 1, grid_top - grid_bottom + 1, 1);
227 Image pix = GridReducedPix(box, gridsize, bleft, left, bottom);
228 int wpl = pixGetWpl(pix);
229 l_uint32 *data = pixGetData(pix);
232 for (
int i = 0;
i < length; ++
i) {
233 int grid_x = (pos.
x() - bleft.
x()) / gridsize - *left;
234 int grid_y = (pos.
y() - bleft.
y()) / gridsize - *bottom;
235 SET_DATA_BIT(data + grid_y * wpl, grid_x);
236 pos += outline->
step(
i);
241 C_OUTLINE_IT ol_it(blob->cblob()->out_list());
242 int grid_left, grid_bottom;
244 &grid_left, &grid_bottom);
245 grid->InsertPixPtBBox(grid_left, grid_bottom, pix, blob);
252 Image pix = GridReducedPix(box, gridsize, bleft, left, bottom);
253 int wpl = pixGetWpl(pix);
254 l_uint32 *data = pixGetData(pix);
256 for (it.mark_cycle_pt(); !it.cycled_list();) {
259 ICOORD next_pos = *it.data();
260 ICOORD line_vector = next_pos - pos;
262 ICOORD major_step, minor_step;
263 line_vector.
setup_render(&major_step, &minor_step, &major, &minor);
264 int accumulator = major / 2;
265 while (pos != next_pos) {
266 int grid_x = (pos.
x() - bleft.
x()) / gridsize - *left;
267 int grid_y = (pos.
y() - bleft.
y()) / gridsize - *bottom;
268 SET_DATA_BIT(data + grid_y * wpl, grid_x);
270 accumulator += minor;
271 if (accumulator >= major) {
272 accumulator -= major;
Image TraceOutlineOnReducedPix(C_OUTLINE *outline, int gridsize, ICOORD bleft, int *left, int *bottom)
Image TraceBlockOnReducedPix(BLOCK *block, int gridsize, ICOORD bleft, int *left, int *bottom)
T ClipToRange(const T &x, const T &lower_bound, const T &upper_bound)
int32_t pathlength() const
const TBOX & bounding_box() const
ICOORD step(int index) const
const ICOORD & start_pos() const
PDBLK pdblk
Page Description Block.
POLY_BLOCK * poly_block() const
void bounding_box(ICOORD &bottom_left, ICOORD &top_right) const
get box
TDimension y() const
access_function
TDimension x() const
access function
void setup_render(ICOORD *major_step, ICOORD *minor_step, int *major, int *minor) const
void rotate(const FCOORD vec)
ICOORDELT_LIST * points()
void rotate(const FCOORD &vec)
const ICOORD & botleft() const
const ICOORD & topright() const
TDimension bottom() const
void ClipGridCoords(int *x, int *y) const
void Init(int gridsize, const ICOORD &bleft, const ICOORD &tright)
const ICOORD & bleft() const
void GridCoords(int x, int y, int *grid_x, int *grid_y) const
const ICOORD & tright() const
IntGrid * NeighbourhoodSum() const
int GridCellValue(int grid_x, int grid_y) const
void Init(int gridsize, const ICOORD &bleft, const ICOORD &tright)
bool RectMostlyOverThreshold(const TBOX &rect, int threshold) const
Image ThresholdToPix(int threshold) const
void Rotate(const FCOORD &rotation)
bool AnyZeroInRect(const TBOX &rect) const