107 constexpr int BM_WORDSIZE = int(
sizeof(potrace_word));
108 constexpr int BM_WORDBITS = 8 * BM_WORDSIZE;
109 constexpr potrace_word BM_HIBIT = potrace_word(1) << (BM_WORDBITS - 1);
112 const int num_words =
bm->dy *
bm->h;
113 const int words_per_scanline =
bm->dy;
123 constexpr bool is_float_color_fn =
124 std::is_invocable_r_v<void, ThresholdFn, const ColorGeometry4f &>;
125 for (const int y : range) {
126 MutableSpan<potrace_word> scanline_words = words.slice(
127 IndexRange(words_per_scanline * y, words_per_scanline));
128 const Span<ColorGeometry4f> scanline_colors = colors.slice(IndexRange(y * ibuf.x, ibuf.x));
129 for (int x = 0; x < ibuf.x; x++) {
130 potrace_word &word = scanline_words[x / BM_WORDBITS];
131 const potrace_word mask = BM_HIBIT >> (x & (BM_WORDBITS - 1));
133 const ColorGeometry4f &fcolor = scanline_colors[x];
135 if constexpr (!is_float_color_fn) {
137 ColorGeometry4b(fcolor.r * 255, fcolor.g * 255, fcolor.b * 255, fcolor.a * 255));
140 is_foreground = fn(fcolor);
159 constexpr bool is_float_color_fn =
160 std::is_invocable_r_v<void, ThresholdFn, const ColorGeometry4f &>;
161 for (const int y : range) {
162 MutableSpan<potrace_word> scanline_words = words.slice(
163 IndexRange(words_per_scanline * y, words_per_scanline));
164 const Span<ColorGeometry4b> scanline_colors = colors.slice(IndexRange(y * ibuf.x, ibuf.x));
165 for (uint32_t x = 0; x < ibuf.x; x++) {
166 potrace_word &word = scanline_words[x / BM_WORDBITS];
167 const potrace_word mask = BM_HIBIT >> (x & (BM_WORDBITS - 1));
169 const ColorGeometry4b bcolor = scanline_colors[x];
171 if constexpr (is_float_color_fn) {
172 is_foreground = fn(ColorGeometry4f(
173 bcolor.r / 255.0f, bcolor.r / 255.0f, bcolor.r / 255.0f, bcolor.r / 255.0f));
176 is_foreground = fn(bcolor);