MayaFlux 0.4.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.

Definition at line 517 of file TextureContainer.cpp.

519{
520 if (data.empty())
521 return;
522 if (region.start_coordinates.size() < 2 || region.end_coordinates.size() < 2)
523 return;
524
525 const uint64_t y0 = region.start_coordinates[0];
526 const uint64_t x0 = region.start_coordinates[1];
527 const uint64_t y1 = std::min(region.end_coordinates[0], static_cast<uint64_t>(m_height - 1));
528 const uint64_t x1 = std::min(region.end_coordinates[1], static_cast<uint64_t>(m_width - 1));
529
530 std::unique_lock lock(m_data_mutex);
531
532 std::visit(
533 [&](auto& dst_vec) {
534 using T = typename std::decay_t<decltype(dst_vec)>::value_type;
535 if constexpr (std::is_same_v<T, uint8_t>
536 || std::is_same_v<T, uint16_t>
537 || std::is_same_v<T, float>) {
538 const auto* src = std::get_if<std::vector<T>>(&data[0]);
539 if (!src || src->empty()) {
541 "TextureContainer::set_region_data source variant does not match "
542 "container element type");
543 return;
544 }
545
546 size_t src_idx = 0;
547 for (uint64_t y = y0; y <= y1 && src_idx < src->size(); ++y) {
548 for (uint64_t x = x0; x <= x1 && src_idx < src->size(); ++x) {
549 const size_t dst_idx = (y * m_width + x) * m_channels;
550 for (uint32_t c = 0; c < m_channels && src_idx < src->size(); ++c, ++src_idx) {
551 if (dst_idx + c < dst_vec.size())
552 dst_vec[dst_idx + c] = (*src)[src_idx];
553 }
554 }
555 }
556 }
557 },
558 m_data[0]);
559
560 m_processed_data[0] = m_data[0];
561}
#define MF_ERROR(comp, ctx,...)
void lock() override
Acquire a lock for thread-safe access.
std::vector< DataVariant > m_processed_data
@ ContainerProcessing
Container operations (Kakshya - file/stream/region processing)
@ Kakshya
Containers[Signalsource, Stream, File], Regions, DataProcessors.

References MayaFlux::Kakshya::Region::end_coordinates, MF_ERROR, and MayaFlux::Kakshya::Region::start_coordinates.