100 gzUInt32 minimumLength, gzUByte *output, gzUInt32 outputCount)
104 if (!validateImage(image, pixels, bytes) || !validAxis(axis) || !minimumLength ||
105 outputCount != pixels || !separate(image.
pixels, bytes, output, outputCount))
108 memset(output, 0, outputCount);
111 for (gzUInt32 line = 0; line < lines; ++line)
113 gzUInt32 position = 0;
114 while (position < extent)
116 if (!at(image, axis, line, position))
122 const gzUInt32 first = position;
123 while (position < extent && at(image, axis, line, position))
125 if (position - first >= minimumLength)
127 for (gzUInt32 i = first; i < position; ++i)
130 line * image.
width + i : i * image.
width + line;
150 gzUInt32 minimumLength, gzUInt32 orthogonalRadius, gzUByte *output, gzUByte *scratch, gzUInt32 outputCount)
154 if (!validateImage(image, pixels, bytes) || !validAxis(axis) || !minimumLength || outputCount != pixels ||
155 !separate(image.
pixels, bytes, output, outputCount) || !separate(image.
pixels, bytes, scratch, outputCount) ||
156 !separate(output, outputCount, scratch, outputCount))
162 const gzUInt32 radius = gzMin(orthogonalRadius, extent - 1);
163 for (gzUInt32 line = 0; line < lines; ++line)
165 gzUInt32 support = 0;
166 for (gzUInt32 position = 0; position <= radius; ++position)
167 support += at(image, across, line, position) != 0;
168 for (gzUInt32 position = 0; position < extent; ++position)
171 line * image.
width + position : position * image.
width + line;
172 scratch[index] = support ? 255 : 0;
173 if (position >= radius)
174 support -= at(image, across, line, position - radius) != 0;
175 if (radius < extent - position - 1)
176 support += at(image, across, line, position + radius + 1) != 0;
180 if (!
retainRuns(corridor, axis, minimumLength, output, outputCount))
182 for (gzUInt32 y = 0; y < image.
height; ++y)
183 for (gzUInt32 x = 0; x < image.
width; ++x)
193 gzUInt32 *output, gzUInt32 outputCount)
197 if (!validateImage(image, pixels, bytes) || !validAxis(axis) ||
199 !aligned(output) || !separate(image.
pixels, bytes, output, (gzUInt64)outputCount *
sizeof(*output)))
202 memset(output, 0, (
size_t)outputCount *
sizeof(*output));
203 for (gzUInt32 y = 0; y < image.
height; ++y)
205 for (gzUInt32 x = 0; x < image.
width; ++x)
224 gzUInt32 *labels, gzUInt32 labelCount, gzUInt32 *queue, gzUInt32 queueCount,
229 if (!validateImage(image, pixels, bytes) ||
231 labelCount != pixels || queueCount < pixels || !aligned(labels) || !aligned(queue) ||
232 !separate(image.
pixels, bytes, labels, (gzUInt64)pixels *
sizeof(*labels)) ||
233 !separate(image.
pixels, bytes, queue, (gzUInt64)pixels *
sizeof(*queue)) ||
234 !separate(labels, (gzUInt64)pixels *
sizeof(*labels), queue, (gzUInt64)pixels *
sizeof(*queue)) ||
235 !separate(image.
pixels, bytes, &componentCount,
sizeof(componentCount)) ||
236 !separate(labels, (gzUInt64)pixels *
sizeof(*labels), &componentCount,
sizeof(componentCount)) ||
237 !separate(queue, (gzUInt64)pixels *
sizeof(*queue), &componentCount,
sizeof(componentCount)))
240 memset(labels, 0, (
size_t)pixels *
sizeof(*labels));
242 for (gzUInt32 seed = 0; seed < pixels; ++seed)
244 const gzUInt32 sx = seed % image.
width, sy = seed / image.
width;
245 if (labels[seed] || !image.
pixels[(gzUInt64)sy * image.
rowStride + sx])
249 gzUInt32 head = 0, tail = 1, maxX = sx, maxY = sy;
251 labels[seed] = count;
254 const gzUInt32 current = queue[head++];
255 const gzUInt32 x = current % image.
width, y = current / image.
width;
256 component.
x = gzMin(component.
x, x);
257 component.
y = gzMin(component.
y, y);
258 maxX = gzMax(maxX, x);
259 maxY = gzMax(maxY, y);
263 for (gzInt32 dy = -1; dy <= 1; ++dy)
265 for (gzInt32 dx = -1; dx <= 1; ++dx)
270 const gzInt32 nx = (gzInt32)x + dx, ny = (gzInt32)y + dy;
271 if (nx < 0 || ny < 0 || (gzUInt32)nx >= image.
width || (gzUInt32)ny >= image.
height)
273 const gzUInt32 next = (gzUInt32)ny * image.
width + (gzUInt32)nx;
274 if (!labels[next] && image.
pixels[(gzUInt64)ny * image.
rowStride + (gzUInt32)nx])
276 labels[next] = count;
277 queue[tail++] = next;
282 component.
width = maxX - component.
x + 1;
283 component.
height = maxY - component.
y + 1;
287 componentCount = count;
303 static gzBool span(
const void *pointer, gzUInt64 bytes, uintptr_t &first, uintptr_t &last)
313 static gzBool separate(
const void *left, gzUInt64 leftBytes,
const void *right, gzUInt64 rightBytes)
315 uintptr_t a, endA, b, endB;
316 return span(left, leftBytes, a, endA) && span(right, rightBytes, b, endB) &&