106 constexpr int BM_WORDSIZE = int(
sizeof(potrace_word));
107 constexpr int BM_WORDBITS = 8 * BM_WORDSIZE;
108 constexpr potrace_word BM_HIBIT = potrace_word(1) << (BM_WORDBITS - 1);
111 const int num_words =
bm->dy *
bm->h;
112 const int words_per_scanline =
bm->dy;
117 if (
const float *float_data = ibuf.
float_data()) {
122 constexpr bool is_float_color_fn =
123 std::is_invocable_r_v<void, ThresholdFn, const ColorGeometry4f &>;
124 for (const int y : range) {
125 MutableSpan<potrace_word> scanline_words = words.slice(
126 IndexRange(words_per_scanline * y, words_per_scanline));
127 const Span<ColorGeometry4f> scanline_colors = colors.slice(IndexRange(y * ibuf.x, ibuf.x));
128 for (int x = 0; x < ibuf.x; x++) {
129 potrace_word &word = scanline_words[x / BM_WORDBITS];
130 const potrace_word mask = BM_HIBIT >> (x & (BM_WORDBITS - 1));
132 const ColorGeometry4f &fcolor = scanline_colors[x];
134 if constexpr (!is_float_color_fn) {
136 ColorGeometry4b(fcolor.r * 255, fcolor.g * 255, fcolor.b * 255, fcolor.a * 255));
139 is_foreground = fn(fcolor);
158 constexpr bool is_float_color_fn =
159 std::is_invocable_r_v<void, ThresholdFn, const ColorGeometry4f &>;
160 for (const int y : range) {
161 MutableSpan<potrace_word> scanline_words = words.slice(
162 IndexRange(words_per_scanline * y, words_per_scanline));
163 const Span<ColorGeometry4b> scanline_colors = colors.slice(IndexRange(y * ibuf.x, ibuf.x));
164 for (uint32_t x = 0; x < ibuf.x; x++) {
165 potrace_word &word = scanline_words[x / BM_WORDBITS];
166 const potrace_word mask = BM_HIBIT >> (x & (BM_WORDBITS - 1));
168 const ColorGeometry4b bcolor = scanline_colors[x];
170 if constexpr (is_float_color_fn) {
171 is_foreground = fn(ColorGeometry4f(
172 bcolor.r / 255.0f, bcolor.r / 255.0f, bcolor.r / 255.0f, bcolor.r / 255.0f));
175 is_foreground = fn(bcolor);