MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ set_region_data()

void MayaFlux::Kakshya::TextureContainer::set_region_data ( const Region &  region,
const std::vector< DataVariant > &  data 
)
overridevirtual

Write DataVariant bytes into the pixel buffer at the region bounds.

The region's SPATIAL_Y / SPATIAL_X coordinates are used as the destination rectangle. The first DataVariant in data must hold std::vector<uint8_t> with exactly region_width * region_height * channels bytes.

Parameters
regionDestination region (start/end SPATIAL_Y, SPATIAL_X coords).
dataSource data. First element must be vector<uint8_t>.

Implements MayaFlux::Kakshya::NDDataContainer< DataVariant >.

Definition at line 741 of file TextureContainer.cpp.

743{
744 if (data.empty())
745 return;
746 if (region.start_coordinates.size() < 2 || region.end_coordinates.size() < 2)
747 return;
748
749 const size_t layer = (m_data.size() > 1 && !region.start_coordinates.empty())
750 ? static_cast<size_t>(region.start_coordinates[0])
751 : 0;
752
753 if (layer >= m_data.size())
754 return;
755
756 ensure_cpu(static_cast<uint32_t>(layer));
757
758 const size_t coord_offset = (m_data.size() > 1) ? 1 : 0;
759 const uint64_t y0 = region.start_coordinates[coord_offset];
760 const uint64_t x0 = region.start_coordinates[coord_offset + 1];
761 const uint64_t y1 = std::min(region.end_coordinates[coord_offset], static_cast<uint64_t>(m_height - 1));
762 const uint64_t x1 = std::min(region.end_coordinates[coord_offset + 1], static_cast<uint64_t>(m_width - 1));
763
764 Memory::SeqlockWriteGuard g(m_slot_locks[layer]);
765 std::visit(
766 [&](auto& dst_vec) {
767 using T = typename std::decay_t<decltype(dst_vec)>::value_type;
768 if constexpr (std::is_same_v<T, uint8_t>
769 || std::is_same_v<T, uint16_t>
770 || std::is_same_v<T, float>) {
771 const auto* src = std::get_if<std::vector<T>>(&data[0]);
772 if (!src || src->empty()) {
774 "TextureContainer::set_region_data source variant does not match "
775 "container element type");
776 return;
777 }
778 size_t src_idx = 0;
779 for (uint64_t y = y0; y <= y1 && src_idx < src->size(); ++y) {
780 for (uint64_t x = x0; x <= x1 && src_idx < src->size(); ++x) {
781 const size_t dst_idx = (y * m_width + x) * m_channels;
782 for (uint32_t c = 0; c < m_channels && src_idx < src->size(); ++c, ++src_idx) {
783 if (dst_idx + c < dst_vec.size())
784 dst_vec[dst_idx + c] = (*src)[src_idx];
785 }
786 }
787 }
788 }
789 },
790 m_data[layer]);
791}
#define MF_ERROR(comp, ctx,...)
const uint32_t * src
void ensure_cpu(uint32_t layer) const
Download a GPU-held layer into m_data before a CPU read.
@ ContainerProcessing
Container operations (Kakshya - file/stream/region processing)
@ Kakshya
Containers[Signalsource, Stream, File], Regions, DataProcessors.

References MayaFlux::Journal::ContainerProcessing, MayaFlux::Kakshya::Region::end_coordinates, ensure_cpu(), MayaFlux::Journal::Kakshya, m_channels, m_data, m_height, m_slot_locks, m_width, MF_ERROR, src, and MayaFlux::Kakshya::Region::start_coordinates.

+ Here is the call graph for this function: