Commit: f8bc7be60fbad611b0d3536f107056f4c382547b Author: Jeroen Bakker Date: Tue Dec 20 15:23:27 2022 +0100 Branches: temp-T101739-fix-seam-bleeding-non-manifold https://developer.blender.org/rBf8bc7be60fbad611b0d3536f107056f4c382547b
Copy pixels classes. =================================================================== M source/blender/blenkernel/CMakeLists.txt A source/blender/blenkernel/intern/pbvh_pixels_copy.cc M source/blender/blenlib/BLI_math_vec_types.hh =================================================================== diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt index c12c0c06ed8..c26c5d1bc4d 100644 --- a/source/blender/blenkernel/CMakeLists.txt +++ b/source/blender/blenkernel/CMakeLists.txt @@ -251,6 +251,7 @@ set(SRC intern/pbvh.cc intern/pbvh_bmesh.c intern/pbvh_pixels.cc + intern/pbvh_pixels_copy.cc intern/pbvh_uv_islands.cc intern/pointcache.c intern/pointcloud.cc diff --git a/source/blender/blenkernel/intern/pbvh_pixels_copy.cc b/source/blender/blenkernel/intern/pbvh_pixels_copy.cc new file mode 100644 index 00000000000..a80e6606037 --- /dev/null +++ b/source/blender/blenkernel/intern/pbvh_pixels_copy.cc @@ -0,0 +1,109 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later + * Copyright 2022 Blender Foundation. All rights reserved. */ + +#include "BLI_math_vec_types.hh" +#include "BLI_vector.hh" +#include "BLI_math.h" + +#include "IMB_imbuf.h" +#include "IMB_imbuf_types.h" + +namespace blender::kernel::pbvh::pixels { +template<typename T, int Channels = 4> struct ImageBufferAccessor { + ImBuf &image_buffer; + + ImageBufferAccessor(ImBuf &image_buffer) : image_buffer(image_buffer) + { + } + + float4 read_pixel(const int2 coordinate) + { + int offset = (coordinate.y * image_buffer.x + coordinate.x) * Channels; + return float4(&image_buffer.rect_float[offset]); + } + + void write_pixel(const int2 coordinate, float4 new_value) + { + int offset = (coordinate.y * image_buffer.x + coordinate.x) * Channels; + copy_v4_v4(&image_buffer.rect_float[offset], new_value); + } +}; + +struct PixelCopyItem { + uint8_t delta_destination_x; + char2 delta_source_1; + char2 delta_source_2; + uint8_t mix_factor; +}; + +struct PixelCopyGroup { + int2 destination; + Vector<PixelCopyItem> items; +}; + +/** Pixel copy command to mix 2 source pixels and write to a destination pixel. */ +struct PixelCopyCommand { + /** Pixel coordinate to write to. */ + int2 destination; + /** Pixel coordinate to read first source from. */ + int2 source_1; + /** Pixel coordinate to read second source from. */ + int2 source_2; + /** Factor to mix between first and second source. */ + float mix_factor; + + PixelCopyCommand(const PixelCopyGroup &group) + : destination(group.destination), + source_1(group.destination), + source_2(group.destination), + mix_factor(0.0f) + { + } + + template<typename T> void mix_source_and_write_destination(ImageBufferAccessor<T> &tile_buffer) const + { + float4 source_color_1 = tile_buffer.read_pixel(source_1); + float4 source_color_2 = tile_buffer.read_pixel(source_2); + float4 destination_color = source_color_1 * (1.0f - mix_factor) + source_color_2 * mix_factor; + tile_buffer.write_pixel(destination, destination_color); + } +}; + +PixelCopyCommand &operator+=(PixelCopyCommand &command, const PixelCopyItem &item) +{ + command.destination.x += int(item.delta_destination_x); + command.source_1 += int2(item.delta_source_1); + command.source_2 += int2(item.delta_source_2); + command.mix_factor = float(item.mix_factor) / 255.0f; + return command; +} + +struct PixelCopyGroups { + Vector<PixelCopyGroup> groups; + + void copy_pixels(ImBuf &tile_buffer) const + { + if (tile_buffer.rect_float) { + ImageBufferAccessor<float4> accessor(tile_buffer); + copy_pixels<float4>(accessor); + } + else { + ImageBufferAccessor<int> accessor(tile_buffer); + copy_pixels<int>(accessor); + } + } + + private: + template<typename T> void copy_pixels(ImageBufferAccessor<T> &image_buffer) const + { + for (const PixelCopyGroup &group : groups) { + PixelCopyCommand copy_command(group); + for (const PixelCopyItem &item : group.items) { + copy_command += item; + copy_command.mix_source_and_write_destination<T>(image_buffer); + } + } + } +}; + +} // namespace blender::kernel::pbvh::pixels diff --git a/source/blender/blenlib/BLI_math_vec_types.hh b/source/blender/blenlib/BLI_math_vec_types.hh index f57b4b44e61..20a8539c67c 100644 --- a/source/blender/blenlib/BLI_math_vec_types.hh +++ b/source/blender/blenlib/BLI_math_vec_types.hh @@ -602,6 +602,7 @@ template<typename T, int Size> struct vec_base : public vec_struct_base<T, Size> } }; +using char2 = blender::vec_base<int8_t, 2>; using char3 = blender::vec_base<int8_t, 3>; using uchar3 = blender::vec_base<uint8_t, 3>; _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs