X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fdata%2Flogicsegment.cpp;h=739b2b9ee2a97652de2d4d4e3530041c1613af2c;hp=22f1d38a0095565cabdeb807180c0e7aff3c934d;hb=HEAD;hpb=bee54d9ec103a35c86fa9e80fbdd2a07f8fb762d diff --git a/pv/data/logicsegment.cpp b/pv/data/logicsegment.cpp index 22f1d38a..739b2b9e 100644 --- a/pv/data/logicsegment.cpp +++ b/pv/data/logicsegment.cpp @@ -63,10 +63,24 @@ LogicSegment::LogicSegment(pv::data::Logic& owner, uint32_t segment_id, LogicSegment::~LogicSegment() { lock_guard lock(mutex_); + for (MipMapLevel &l : mip_map_) free(l.data); } +shared_ptr LogicSegment::get_shared_ptr() const +{ + shared_ptr ptr = nullptr; + + try { + ptr = shared_from_this(); + } catch (std::exception& e) { + /* Do nothing, ptr remains a null pointer */ + } + + return ptr ? std::dynamic_pointer_cast(ptr) : nullptr; +} + template void LogicSegment::downsampleTmain(const T*&in, T &acc, T &prev) { @@ -349,6 +363,31 @@ void LogicSegment::append_payload(void *data, uint64_t data_size) prev_sample_count + 1, prev_sample_count + 1); } +void LogicSegment::append_subsignal_payload(unsigned int index, void *data, + uint64_t data_size, vector& destination) +{ + if (index == 0) + destination.resize(data_size * unit_size_, 0); + + // Set the bits for this sub-signal where needed + // Note: the bytes in *data must either be 0 or 1, nothing else + unsigned int index_byte_offs = index / 8; + uint8_t* output_data = destination.data() + index_byte_offs; + uint8_t* input_data = (uint8_t*)data; + + for (uint64_t i = 0; i < data_size; i++) { + assert((i * unit_size_ + index_byte_offs) < destination.size()); + *output_data |= (input_data[i] << index); + output_data += unit_size_; + } + + if (index == owner_.num_channels() - 1) { + // We gathered sample data of all sub-signals, let's append it + append_payload(destination.data(), destination.size()); + destination.clear(); + } +} + void LogicSegment::get_samples(int64_t start_sample, int64_t end_sample, uint8_t* dest) const { @@ -629,7 +668,7 @@ void LogicSegment::append_payload_to_mipmap() else if (unit_size_ == 4) downsampleT(src_ptr, dest_ptr, count); else if (unit_size_ == 8) - downsampleT(src_ptr, dest_ptr, count); + downsampleT(src_ptr, dest_ptr, count); else downsampleGeneric(src_ptr, dest_ptr, count); len_sample -= count;