Blender V5.3
pbvh_pixels_copy.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <algorithm>
10
11#include "BLI_array.hh"
12#include "BLI_index_mask.hh"
13#include "BLI_listbase.hh"
14#include "BLI_math_color_c.hh"
15#include "BLI_math_geom_c.hh"
16#include "BLI_math_vector.hh"
17#include "BLI_task.hh"
18#include "BLI_vector.hh"
19
20#include "IMB_imbuf.hh"
21#include "IMB_imbuf_types.hh"
22
23#include "BKE_image_wrappers.hh"
24#include "BKE_mesh.hh"
25#include "BKE_paint_bvh.hh"
27
28#include "PRF_profile.hh"
29
30#include "pbvh_pixels_copy.hh"
31#include "pbvh_uv_islands.hh"
32
34
35const int THREADING_GRAIN_SIZE = 128;
36
38enum class CoordSpace {
43
51};
52
53template<CoordSpace Space> struct Vertex {
55};
56
57template<CoordSpace Space> struct Edge {
60};
61
63static rcti get_bounds(const Edge<CoordSpace::Tile> &tile_edge)
64{
67 BLI_rcti_do_minmax_v(&bounds, int2(tile_edge.vertex_1.coordinate));
68 BLI_rcti_do_minmax_v(&bounds, int2(tile_edge.vertex_2.coordinate));
69 return bounds;
70}
71
73static void add_margin(rcti &bounds, int margin)
74{
75 bounds.xmin -= margin;
76 bounds.xmax += margin;
77 bounds.ymin -= margin;
78 bounds.ymax += margin;
79}
80
82static void clamp(rcti &bounds, int2 resolution)
83{
84 rcti clamping_bounds;
85 BLI_rcti_init(&clamping_bounds, 0, resolution.x - 1, 0, resolution.y - 1);
86 BLI_rcti_isect(&bounds, &clamping_bounds, &bounds);
87}
88
90 const image::ImageTileWrapper image_tile,
91 const int2 tile_resolution)
92{
93 return Vertex<CoordSpace::Tile>{(uv_vertex.coordinate - float2(image_tile.get_tile_offset())) *
94 float2(tile_resolution)};
95}
96
98 const image::ImageTileWrapper image_tile,
99 const int2 tile_resolution)
100{
102 convert_coord_space(uv_edge.vertex_1, image_tile, tile_resolution),
103 convert_coord_space(uv_edge.vertex_2, image_tile, tile_resolution),
104 };
105}
106
107class NonManifoldTileEdges : public Vector<Edge<CoordSpace::Tile>> {};
108
109class NonManifoldUVEdges : public Vector<Edge<CoordSpace::UV>> {
110 public:
112 {
113 int num_non_manifold_edges = count_non_manifold_edges(mesh_data);
114 reserve(num_non_manifold_edges);
115 for (const int primitive_id : mesh_data.corner_tris.index_range()) {
116 const int3 tri = mesh_data.corner_tris[primitive_id];
117 const int3 real_edges = mesh::corner_tri_get_real_edges(
118 mesh_data.mesh_edges, mesh_data.corner_verts, mesh_data.corner_edges, tri);
119 for (int j = 0; j < 3; j++) {
120 const int edge_id = real_edges[j];
121 /* -1 means internal edge in face, which is always manifold. */
122 if (edge_id == -1 || mesh_data.is_edge_manifold(edge_id)) {
123 continue;
124 }
126 edge.vertex_1.coordinate = mesh_data.uv_map[tri[j]];
127 edge.vertex_2.coordinate = mesh_data.uv_map[tri[(j + 1) % 3]];
128 append(edge);
129 }
130 }
131 BLI_assert_msg(size() == num_non_manifold_edges,
132 "Incorrect number of non manifold edges added. ");
133 }
134
136 const int2 tile_resolution) const
137 {
139 for (const Edge<CoordSpace::UV> &uv_edge : *this) {
141 uv_edge, image_tile, tile_resolution);
142 result.append(tile_edge);
143 }
144 return result;
145 }
146
147 private:
148 static int64_t count_non_manifold_edges(const uv_islands::MeshData &mesh_data)
149 {
150 int64_t result = 0;
151 for (const int primitive_id : mesh_data.corner_tris.index_range()) {
152 const int3 real_edges = mesh::corner_tri_get_real_edges(mesh_data.mesh_edges,
153 mesh_data.corner_verts,
154 mesh_data.corner_edges,
155 mesh_data.corner_tris[primitive_id]);
156 for (int j = 0; j < 3; j++) {
157 const int edge_id = real_edges[j];
158 /* -1 means internal edge in face, which is always manifold. */
159 if (!(edge_id == -1 || mesh_data.is_edge_manifold(edge_id))) {
160 result += 1;
161 }
162 }
163 }
164 return result;
165 }
166};
167
168class PixelNodesTileData : public Vector<std::reference_wrapper<UDIMTilePixels>> {
169 public:
171 {
172 IndexMaskMemory memory;
173 const IndexMask nodes = affected_nodes(pbvh, image_tile, memory);
174 reserve(nodes.size());
175
176 PixelData &pixel_data = *pbvh.pixels_;
177 MutableSpan<PixelNode> pixel_nodes = pixel_data.nodes;
178
179 nodes.foreach_index([&](const int i) { append(*pixel_nodes[i].find_tile_data(image_tile)); });
180 }
181
182 private:
183 static bool should_add_node(PixelNode &node, const image::ImageTileWrapper &image_tile)
184 {
185 if (node.find_tile_data(image_tile) == nullptr) {
186 return false;
187 }
188 return true;
189 }
190
191 static IndexMask affected_nodes(bke::pbvh::Tree &pbvh,
192 const image::ImageTileWrapper &image_tile,
193 IndexMaskMemory &memory)
194 {
195 IndexMask leaf_nodes = all_leaf_nodes(pbvh, memory);
196 PixelData &pixel_data = *pbvh.pixels_;
197 MutableSpan<PixelNode> pixel_nodes = pixel_data.nodes;
198
199 return IndexMask::from_predicate(leaf_nodes, memory, [&](const int i) {
200 return should_add_node(pixel_nodes[i], image_tile);
201 });
202 }
203};
204
216
218 const CopyPixelCommand &next)
219{
220 return DeltaCopyPixelCommand(char2(next.source_1 - previous.source_1),
221 char2(next.source_2 - next.source_1),
222 uint8_t(next.mix_factor * 255));
223}
224
226static bool can_be_extended(const CopyPixelCommand &previous, const CopyPixelCommand &next)
227{
228 /* Can only extend sequential pixels. */
229 if (previous.destination.x != next.destination.x - 1 ||
230 previous.destination.y != next.destination.y)
231 {
232 return false;
233 }
234
235 /* Can only extend when the delta between with the previous source fits in a single byte. */
236 const int2 delta_source_1 = previous.source_1 - next.source_1;
237 return math::reduce_max(math::abs(delta_source_1)) <= 127;
238}
239
244
245struct Rows {
246 enum class PixelType : uint8_t {
247 Undecided,
250 SelectedForCloserExamination,
252 CopyFromClosestEdge,
253 };
254
255 struct Pixel {
256 float distance = std::numeric_limits<float>::max();
263 int edge_index = -1;
265 };
266
270
275
277 {
278 return int2(int(index % resolution.x), int(index / resolution.x));
279 }
280
286 {
287 for (const UDIMTilePixels &tile_pixels : nodes_tile_pixels) {
288 const int num_runs = tile_pixels.pixel_row_run_starts.size() - 1;
289 threading::parallel_for(IndexRange(num_runs), 64, [&](const IndexRange range) {
290 for (const int run_i : range) {
291 int x = tile_pixels.pixel_row_run_start_coords[run_i].x;
292 const int y = tile_pixels.pixel_row_run_start_coords[run_i].y;
293 const int run_begin = tile_pixels.pixel_row_run_starts[run_i];
294 const int run_end = tile_pixels.pixel_row_run_starts[run_i + 1];
295 for (int k = run_begin; k < run_end; k++) {
296 const int num_pixels = tile_pixels.pixel_rows[k].num_pixels;
297 for (int px = 0; px < num_pixels; px++, x++) {
300 pixels[index].distance = 0.0f;
301 }
302 }
303 }
304 });
305 }
306 }
307
318 int2 find_second_source(int2 destination, int2 first_source)
319 {
320 rcti search_bounds;
321 BLI_rcti_init(&search_bounds,
322 max_ii(first_source.x - 1, 0),
323 min_ii(first_source.x + 1, resolution.x - 1),
324 max_ii(first_source.y - 1, 0),
325 min_ii(first_source.y + 1, resolution.y - 1));
326 /* Initialize to the first source, so when no other source could be found it will use the
327 * first_source. */
328 int2 found_source = first_source;
329 float found_distance = std::numeric_limits<float>::max();
330 for (int sy : IndexRange(search_bounds.ymin, BLI_rcti_size_y(&search_bounds) + 1)) {
331 for (int sx : IndexRange(search_bounds.xmin, BLI_rcti_size_x(&search_bounds) + 1)) {
332 int2 source(sx, sy);
333 /* Skip first source as it should be the closest and already selected. */
334 if (source == first_source) {
335 continue;
336 }
337 int pixel_index = sy * resolution.x + sx;
338 if (pixels[pixel_index].type != PixelType::Brush) {
339 continue;
340 }
341
342 float new_distance = math::distance(float2(destination), float2(source));
343 if (new_distance < found_distance) {
344 found_distance = new_distance;
345 found_source = source;
346 }
347 }
348 }
349 return found_source;
350 }
351
352 float determine_mix_factor(const int2 destination,
353 const int2 source_1,
354 const int2 source_2,
355 const Edge<CoordSpace::Tile> &edge)
356 {
357 /* Use stable result when both sources are the same. */
358 if (source_1 == source_2) {
359 return 0.0f;
360 }
361
362 float2 clamped_to_edge;
363 float destination_lambda = closest_to_line_v2(
364 clamped_to_edge, float2(destination), edge.vertex_1.coordinate, edge.vertex_2.coordinate);
365 float source_1_lambda = closest_to_line_v2(
366 clamped_to_edge, float2(source_1), edge.vertex_1.coordinate, edge.vertex_2.coordinate);
367 float source_2_lambda = closest_to_line_v2(
368 clamped_to_edge, float2(source_2), edge.vertex_1.coordinate, edge.vertex_2.coordinate);
369
370 return clamp_f(
371 (destination_lambda - source_1_lambda) / (source_2_lambda - source_1_lambda), 0.0f, 1.0f);
372 }
373
375 CopyPixelCommand &r_command,
376 const NonManifoldTileEdges &tile_edges)
377 {
378 Pixel &pixel = pixels[index];
380 const int2 destination = coordinate_of(index);
381
382 rcti bounds;
383 BLI_rcti_init(&bounds, destination.x, destination.x, destination.y, destination.y);
386
387 float found_distance = std::numeric_limits<float>::max();
388 int2 found_source(0);
389
390 for (int sy : IndexRange(bounds.ymin, BLI_rcti_size_y(&bounds))) {
391 int pixel_index = sy * resolution.x;
392 for (int sx : IndexRange(bounds.xmin, BLI_rcti_size_x(&bounds))) {
393 Pixel &source = pixels[pixel_index + sx];
394 if (source.type != PixelType::Brush) {
395 continue;
396 }
397 float new_distance = math::distance(float2(sx, sy), float2(destination));
398 if (new_distance < found_distance) {
399 found_source = int2(sx, sy);
400 found_distance = new_distance;
401 }
402 }
403 }
404
405 if (found_distance == std::numeric_limits<float>::max()) {
406 return;
407 }
409 pixel.distance = found_distance;
410 r_command.destination = destination;
411 r_command.source_1 = found_source;
412 r_command.source_2 = find_second_source(destination, found_source);
414 destination, found_source, r_command.source_2, tile_edges[pixel.edge_index]);
415 }
416
417 void find_copy_source(const Span<int64_t> selected_pixels,
419 const NonManifoldTileEdges &tile_edges)
420 {
422 selected_pixels.index_range(), THREADING_GRAIN_SIZE, [&](IndexRange range) {
423 for (const int64_t i : range) {
424 find_copy_source(selected_pixels[i], r_commands[i], tile_edges);
425 }
426 });
427 }
428
430 {
431 Vector<int64_t> selected_pixels;
432 selected_pixels.reserve(10000);
433
434 for (int tile_edge_index : tile_edges.index_range()) {
435 const Edge<CoordSpace::Tile> &tile_edge = tile_edges[tile_edge_index];
436 rcti edge_bounds = get_bounds(tile_edge);
437 add_margin(edge_bounds, margin);
438 clamp(edge_bounds, resolution);
439
440 for (const int64_t sy : IndexRange(edge_bounds.ymin, BLI_rcti_size_y(&edge_bounds))) {
441 for (const int64_t sx : IndexRange(edge_bounds.xmin, BLI_rcti_size_x(&edge_bounds))) {
442 const int64_t index = sy * resolution.x + sx;
443 Pixel &pixel = pixels[index];
444 if (pixel.type == PixelType::Brush) {
445 continue;
446 }
448 "PixelType::CopyFromClosestEdge isn't allowed to be set as it is set "
449 "when finding the pixels to copy.");
450
451 const float2 point(sx, sy);
452 float2 closest_edge_point;
453 closest_to_line_segment_v2(closest_edge_point,
454 point,
455 tile_edge.vertex_1.coordinate,
456 tile_edge.vertex_2.coordinate);
457 float distance_to_edge = math::distance(closest_edge_point, point);
458 if (distance_to_edge < margin && distance_to_edge < pixel.distance) {
460 selected_pixels.append(index);
461 }
463 pixel.distance = distance_to_edge;
464 pixel.edge_index = tile_edge_index;
465 }
466 }
467 }
468 }
469 return selected_pixels;
470 }
471
472 void pack_into(const Span<int64_t> selected_pixels,
473 const Span<CopyPixelCommand> commands,
474 CopyPixelTile &copy_tile) const
475 {
476 std::optional<std::reference_wrapper<CopyPixelGroup>> last_group = std::nullopt;
477 std::optional<CopyPixelCommand> last_command = std::nullopt;
478 const int seam_tilex_x = (resolution.x + SEAM_TILE_SIZE - 1) >> SEAM_TILE_BITS;
479 int last_seam_tile = -1;
480
481 for (const int64_t i : selected_pixels.index_range()) {
482 if (pixels[selected_pixels[i]].type == PixelType::CopyFromClosestEdge) {
483 const CopyPixelCommand &command = commands[i];
484
485 /* Split group when it cross into another seam tile, so we can cleanly
486 * sort each group into a seam tile later. */
487 const int seam_tile = CopyPixelTile::seam_tile_index(command.source_1, seam_tilex_x);
488 if (!last_command.has_value() || !can_be_extended(*last_command, command) ||
489 seam_tile != last_seam_tile)
490 {
491 CopyPixelGroup new_group = {command.destination - int2(1, 0),
492 command.source_1,
493 copy_tile.command_deltas.size(),
494 0};
495 last_seam_tile = seam_tile;
496 copy_tile.groups.append(new_group);
497 last_group = copy_tile.groups.last();
498 last_command = CopyPixelCommand{.destination = new_group.start_destination,
499 .source_1 = new_group.start_source_1,
500 .source_2 = int2(0),
501 .mix_factor = 0.0f};
502 }
503
504 DeltaCopyPixelCommand delta_command = encode_delta(*last_command, command);
505 copy_tile.command_deltas.append(delta_command);
506 last_group->get().num_deltas++;
507 last_command = command;
508 }
509 }
510 }
511};
512
514{
515 /* Sort the groups by the seam tile their source pixels fall in and
516 * store the index range into the group array for each seam tile. */
517 const int tiles_x = (resolution.x + SEAM_TILE_SIZE - 1) >> SEAM_TILE_BITS;
518 std::ranges::stable_sort(groups, std::less<>{}, [tiles_x](const CopyPixelGroup &group) {
519 return seam_tile_index(group.start_source_1, tiles_x);
520 });
521
522 seam_tile_to_groups.clear();
523 int64_t start = 0;
524 while (start < groups.size()) {
525 const int tile = seam_tile_index(groups[start].start_source_1, tiles_x);
526 int64_t end = start + 1;
527 while (end < groups.size() && seam_tile_index(groups[end].start_source_1, tiles_x) == tile) {
528 end++;
529 }
530 seam_tile_to_groups.add(tile, IndexRange(start, end - start));
531 start = end;
532 }
533}
534
535static int64_t pixel_offset(const int width, const int2 coordinate)
536{
537 return (int64_t(coordinate.y) * width + coordinate.x) * 4;
538}
539
540static float4 read_pixel(const float *buffer, const int width, const int2 coordinate)
541{
542 return float4(&buffer[pixel_offset(width, coordinate)]);
543}
544
545static void write_pixel(float *buffer, const int width, const int2 coordinate, const float4 &value)
546{
547 std::copy_n(&value.x, 4, &buffer[pixel_offset(width, coordinate)]);
548}
549
550static float4 read_pixel(const uint8_t *buffer, const int width, const int2 coordinate)
551{
553 rgba_uchar_to_float(result, &buffer[pixel_offset(width, coordinate)]);
554 return result;
555}
556
557static void write_pixel(uint8_t *buffer,
558 const int width,
559 const int2 coordinate,
560 const float4 &value)
561{
562 rgba_float_to_uchar(&buffer[pixel_offset(width, coordinate)], value);
563}
564
565template<typename T>
566static void copy_pixels(T *buffer,
567 const int width,
568 const Span<CopyPixelGroup> groups,
569 const Span<DeltaCopyPixelCommand> command_deltas)
570{
571 for (const CopyPixelGroup &group : groups) {
572 CopyPixelCommand command{.destination = group.start_destination,
573 .source_1 = group.start_source_1,
574 .source_2 = group.start_source_1,
575 .mix_factor = 0.0f};
576
577 for (const DeltaCopyPixelCommand &delta :
578 Span(&command_deltas[group.start_delta_index], group.num_deltas))
579 {
580 command.destination.x += 1;
581 command.source_1 += int2(delta.delta_source_1);
582 command.source_2 = command.source_1 + int2(delta.delta_source_2);
583 command.mix_factor = float(delta.mix_factor) / 255.0f;
584
585 const float4 src_color_1 = read_pixel(buffer, width, command.source_1);
586 const float4 src_color_2 = read_pixel(buffer, width, command.source_2);
587 const float4 dst_color = math::interpolate(src_color_1, src_color_2, command.mix_factor);
588 write_pixel(buffer, width, command.destination, dst_color);
589 }
590 }
591}
592
593void CopyPixelTile::copy_pixels(ImBuf &tile_buffer, const IndexRange group_range) const
594{
595 BLI_assert(tile_buffer.channels == 4);
596 if (tile_buffer.float_data()) {
598 tile_buffer.x,
599 groups.as_span().slice(group_range),
601 }
602 else {
604 tile_buffer.x,
605 groups.as_span().slice(group_range),
607 }
608}
609
611{
612 const int decoded_size = command_deltas.size() * int(sizeof(CopyPixelCommand));
613 const int encoded_size = groups.size() * int(sizeof(CopyPixelGroup)) +
614 command_deltas.size() * int(sizeof(DeltaCopyPixelCommand));
615 printf("Tile %d compression rate: %d->%d = %d%%\n",
617 decoded_size,
618 encoded_size,
619 int(100.0 * float(encoded_size) / float(decoded_size)));
620}
621
623 Image &image,
624 const ImageUser &image_user,
625 const uv_islands::MeshData &mesh_data)
626{
628 PixelData &pbvh_data = data_get(pbvh);
629 pbvh_data.tiles_copy_pixels.clear();
630 const NonManifoldUVEdges non_manifold_edges(mesh_data);
631 if (non_manifold_edges.is_empty()) {
632 /* Early exit: No non manifold edges detected. */
633 return;
634 }
635
636 ImageUser tile_user = image_user;
637 for (ImageTile &tile : image.tiles) {
639 tile_user.tile = image_tile.get_tile_number();
640
641 ImBuf *tile_buffer = BKE_image_acquire_ibuf(&image, &tile_user, nullptr);
642 if (tile_buffer == nullptr) {
643 continue;
644 }
645 const PixelNodesTileData nodes_tile_pixels(pbvh, image_tile);
646
647 int2 tile_resolution(tile_buffer->x, tile_buffer->y);
648 BKE_image_release_ibuf(&image, tile_buffer, nullptr);
649
650 NonManifoldTileEdges tile_edges = non_manifold_edges.extract_tile_edges(image_tile,
651 tile_resolution);
652 CopyPixelTile copy_tile(image_tile.get_tile_number());
653
654 Rows rows(tile_resolution, image.seam_margin);
655 rows.mark_pixels_effected_by_brush(nodes_tile_pixels);
656
657 Vector<int64_t> selected_pixels = rows.filter_pixels_for_closer_examination(tile_edges);
658 Array<CopyPixelCommand> selected_commands(selected_pixels.size());
659 rows.find_copy_source(selected_pixels, selected_commands, tile_edges);
660 rows.pack_into(selected_pixels, selected_commands, copy_tile);
661 copy_tile.build_seam_tile_map(tile_resolution);
662
663 // copy_tile.print_compression_rate();
664 pbvh_data.tiles_copy_pixels.tiles.append(copy_tile);
665 }
666}
667
668/* TODO: Allow passing `ImageData` here, but this requires pulling this entire class out of the
669 * bke namespace. */
672 image::TileNumber tile_number,
673 const Span<uint8_t> seam_tiles_modified,
674 const FunctionRef<void(int x_start, int x_end, int y)> push_undo_tiles)
675{
676 PixelData &pbvh_data = data_get(pbvh);
677 std::optional<std::reference_wrapper<CopyPixelTile>> pixel_tile =
678 pbvh_data.tiles_copy_pixels.find_tile(tile_number);
679 if (!pixel_tile.has_value()) {
680 /* No pixels need to be copied. */
681 return;
682 }
683
684 ImBuf *tile_buffer = buffers.lookup_default(tile_number, nullptr);
685 if (tile_buffer == nullptr) {
686 /* No tile buffer found to copy. */
687 return;
688 }
689
690 CopyPixelTile &tile = pixel_tile->get();
691
692 /* Apply the pixel copies for groups whose seam tile was modified. */
693 for (const auto item : tile.seam_tile_to_groups.items()) {
694 BLI_assert(item.key < seam_tiles_modified.size());
695 if (!seam_tiles_modified[item.key]) {
696 continue;
697 }
698 const IndexRange group_range = item.value;
699
700 /* Push undo tiles affected by these groups before editing, just like painting. */
701 for (const CopyPixelGroup &group : tile.groups.as_span().slice(group_range)) {
702 push_undo_tiles(group.start_destination.x + 1,
703 group.start_destination.x + group.num_deltas,
704 group.start_destination.y);
705 }
706
707 tile.copy_pixels(*tile_buffer, group_range);
708 }
709}
710
711} // namespace blender::bke::pbvh::pixels
A BVH for high poly meshes.
#define PRF_scope(category)
#define BLI_assert_msg(a, msg)
constexpr Span()=default
static IndexMask from_predicate(const IndexMask &universe, LinearAllocator<> &memory, Fn &&predicate, exec_mode::Mode mode=exec_mode::parallel)
constexpr IndexRange()=default
Value lookup_default(const Key &key, const Value &default_value) const
Definition BLI_map.hh:570
constexpr int64_t size() const
Definition BLI_span.hh:256
constexpr IndexRange index_range() const
Definition BLI_span.hh:405
int64_t size() const
void append(const T &value)
void reserve(const int64_t min_capacity)
NonManifoldTileEdges extract_tile_edges(const image::ImageTileWrapper image_tile, const int2 tile_resolution) const
NonManifoldUVEdges(const uv_islands::MeshData &mesh_data)
PixelNodesTileData(bke::pbvh::Tree &pbvh, const image::ImageTileWrapper &image_tile)
void append(const Edge< CoordSpace::UV > &value)
IndexRange index_range() const
const ccl_global KernelWorkTile * tile
#define T
int3 corner_tri_get_real_edges(Span< int2 > edges, Span< int > corner_verts, Span< int > corner_edges, const int3 &corner_tri)
static void clamp(rcti &bounds, int2 resolution)
static bool can_be_extended(const CopyPixelCommand &previous, const CopyPixelCommand &next)
PixelData & data_get(bke::pbvh::Tree &pbvh)
static Vertex< CoordSpace::Tile > convert_coord_space(const Vertex< CoordSpace::UV > &uv_vertex, const image::ImageTileWrapper image_tile, const int2 tile_resolution)
static float4 read_pixel(const float *buffer, const int width, const int2 coordinate)
static void add_margin(rcti &bounds, int margin)
static rcti get_bounds(const Edge< CoordSpace::Tile > &tile_edge)
static DeltaCopyPixelCommand encode_delta(const CopyPixelCommand &previous, const CopyPixelCommand &next)
static void write_pixel(float *buffer, const int width, const int2 coordinate, const float4 &value)
void copy_pixels(bke::pbvh::Tree &pbvh, Map< image::TileNumber, ImBuf * > &buffers, image::TileNumber tile_number, Span< uint8_t > seam_tiles_modified, FunctionRef< void(int x_start, int x_end, int y)> push_undo_tiles)
void copy_update(bke::pbvh::Tree &pbvh, Image &image, const ImageUser &image_user, const uv_islands::MeshData &mesh_data)
static int64_t pixel_offset(const int width, const int2 coordinate)
IndexMask all_leaf_nodes(const Tree &pbvh, IndexMaskMemory &memory)
Definition pbvh.cc:2522
T reduce_max(const VecBase< T, Size > &a)
T distance(const T &a, const T &b)
T interpolate(const T &a, const T &b, const FactorT &t)
T abs(const T &a)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
Definition BLI_task.hh:69
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
__int64 int64_t
Definition BKE_text.h:90
MINLINE void rgba_uchar_to_float(float r_col[4], const unsigned char col_ub[4])
bool BLI_rcti_isect(const struct rcti *src1, const struct rcti *src2, struct rcti *dest)
VecBase< int8_t, 2 > char2
void BLI_rcti_init_minmax(struct rcti *rect)
Definition rct.cc:488
MINLINE int max_ii(int a, int b)
void BLI_rcti_do_minmax_v(struct rcti *rect, const int xy[2])
Definition rct.cc:500
VecBase< float, 4 > float4
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
Definition BLI_rect.hh:207
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
VecBase< int32_t, 3 > int3
unsigned char uint8_t
Definition BKE_text.h:79
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
Definition BLI_rect.hh:203
void BLI_rcti_init(struct rcti *rect, int xmin, int xmax, int ymin, int ymax)
Definition rct.cc:428
ImBuf * BKE_image_acquire_ibuf(Image *ima, ImageUser *iuser, void **r_lock)
float closest_to_line_v2(float r_close[2], const float p[2], const float l1[2], const float l2[2])
float closest_to_line_segment_v2(float r_close[2], const float p[2], const float l1[2], const float l2[2])
Definition math_geom.cc:381
MINLINE int min_ii(int a, int b)
MINLINE void rgba_float_to_uchar(unsigned char r_col[4], const float col_f[4])
MINLINE float clamp_f(float value, float min, float max)
void BKE_image_release_ibuf(Image *ima, ImBuf *ibuf, void *lock)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
uint8_t * byte_data_for_write()
Definition allocimbuf.cc:60
const float * float_data() const
float * float_data_for_write()
Definition allocimbuf.cc:79
void build_seam_tile_map(const int2 resolution)
static int seam_tile_index(const int2 source, const int seam_tiles_x)
Vector< DeltaCopyPixelCommand > command_deltas
void copy_pixels(ImBuf &tile_buffer, IndexRange group_range) const
std::optional< std::reference_wrapper< CopyPixelTile > > find_tile(image::TileNumber tile_number)
DeltaCopyPixelCommand(char2 delta_source_1, char2 delta_source_2, uint8_t mix_factor)
Vector< int64_t > filter_pixels_for_closer_examination(const NonManifoldTileEdges &tile_edges)
void find_copy_source(const Span< int64_t > selected_pixels, MutableSpan< CopyPixelCommand > r_commands, const NonManifoldTileEdges &tile_edges)
void mark_pixels_effected_by_brush(const PixelNodesTileData &nodes_tile_pixels)
int2 coordinate_of(const int64_t index) const
Rows(int2 resolution, int margin)
float determine_mix_factor(const int2 destination, const int2 source_1, const int2 source_2, const Edge< CoordSpace::Tile > &edge)
int2 find_second_source(int2 destination, int2 first_source)
void find_copy_source(const int64_t index, CopyPixelCommand &r_command, const NonManifoldTileEdges &tile_edges)
void pack_into(const Span< int64_t > selected_pixels, const Span< CopyPixelCommand > commands, CopyPixelTile &copy_tile) const
bool is_edge_manifold(const int edge_id) const