23 #include "allheaders.h"
29 #define FLIP_COLOUR(pix) (1-(pix))
39 C_OUTLINE_IT* outline_it) {
44 int width = pixGetWidth(t_pix);
45 int height = pixGetHeight(t_pix);
46 int wpl = pixGetWpl(t_pix);
48 std::unique_ptr<CRACKEDGE*[]> ptrline(
new CRACKEDGE*[width + 1]);
54 int block_width = tright.
x() - bleft.
x();
55 for (
int x = block_width; x >= 0; x--)
58 std::unique_ptr<uint8_t[]> bwline(
new uint8_t[width]);
62 for (
int y = tright.
y() - 1; y >= bleft.
y() - 1; y--) {
63 if (y >= bleft.
y() && y < tright.
y()) {
65 l_uint32* line = pixGetData(t_pix) + wpl * (height - 1 - y);
66 for (
int x = 0; x < block_width; ++x) {
67 bwline[x] = GET_DATA_BIT(line, x + bleft.
x()) ^ 1;
69 make_margins(block, &line_it, bwline.get(), margin, bleft.
x(), tright.
x(), y);
71 memset(bwline.get(), margin, block_width *
sizeof(bwline[0]));
74 margin, bwline.get(), ptrline.get(), &free_cracks, outline_it);
103 const std::unique_ptr< ICOORDELT_LIST> segments(
105 if (!segments->empty ()) {
106 seg_it.set_to_list(segments.get());
107 seg_it.mark_cycle_pt ();
108 start = seg_it.data ()->x ();
109 xext = seg_it.data ()->y ();
110 for (xindex = left; xindex < right; xindex++) {
111 if (xindex >= start && !seg_it.cycled_list ()) {
112 xindex = start + xext - 1;
114 start = seg_it.data ()->x ();
115 xext = seg_it.data ()->y ();
118 pixels[xindex - left] = margin;
122 for (xindex = left; xindex < right; xindex++)
123 pixels[xindex - left] = margin;
127 start = line_it->
get_line (y, xext);
128 for (xindex = left; xindex < start; xindex++)
129 pixels[xindex - left] = margin;
130 for (xindex = start + xext; xindex < right; xindex++)
131 pixels[xindex - left] = margin;
149 C_OUTLINE_IT* outline_it) {
150 CrackPos pos = {free_cracks, x, y };
157 prevcolour = uppercolour;
161 for (; pos.
x < xmax; pos.
x++, prevline++) {
162 const int colour = *bwpos++;
163 if (*prevline !=
nullptr) {
167 if (colour == prevcolour) {
168 if (colour == uppercolour) {
170 join_edges(current, *prevline, free_cracks, outline_it);
174 current =
h_edge(uppercolour - colour, *prevline, &pos);
178 if (colour == uppercolour)
179 *prevline =
v_edge(colour - prevcolour, *prevline, &pos);
182 join_edges(current, *prevline, free_cracks, outline_it);
183 current =
h_edge(uppercolour - colour,
nullptr, &pos);
184 *prevline =
v_edge(colour - prevcolour, current, &pos);
186 newcurrent =
h_edge(uppercolour - colour, *prevline, &pos);
187 *prevline =
v_edge(colour - prevcolour, current, &pos);
188 current = newcurrent;
193 if (colour != prevcolour) {
194 *prevline = current =
v_edge(colour - prevcolour, current, &pos);
197 if (colour != uppercolour)
198 current =
h_edge(uppercolour - colour, current, &pos);
203 if (current !=
nullptr) {
205 if (*prevline !=
nullptr) {
206 join_edges(current, *prevline, free_cracks, outline_it);
212 }
else if (*prevline !=
nullptr) {
249 if (join ==
nullptr) {
254 && newpt->
pos.
y() == join->
pos.
y()) {
300 if (join ==
nullptr) {
331 C_OUTLINE_IT* outline_it) {
339 if (edge1->
next == edge2) {
344 *free_cracks = edge1;
365 for (current = start; current !=
nullptr; current = next) {
366 next = current->
next;