]> sigrok.org Git - pulseview.git/blobdiff - pv/data/logicsnapshot.cpp
Various tidyups in LogicSnapshot
[pulseview.git] / pv / data / logicsnapshot.cpp
index 5665d35f8c3d58916b3df6ed41c11227f13d39cf..e6fd26e33b68f742a8547894487ddf7f719a5bd3 100644 (file)
@@ -70,14 +70,17 @@ void LogicSnapshot::append_payload(
        append_payload_to_mipmap();
 }
 
-void LogicSnapshot::reallocate_mip_map(MipMapLevel &m)
+void LogicSnapshot::reallocate_mipmap_level(MipMapLevel &m)
 {
        const uint64_t new_data_length = ((m.length + MipMapDataUnit - 1) /
                MipMapDataUnit) * MipMapDataUnit;
        if (new_data_length > m.data_length)
        {
                m.data_length = new_data_length;
-               m.data = realloc(m.data, new_data_length * _unit_size);
+
+               // Padding is added to allow for the uint64_t write word
+               m.data = realloc(m.data, new_data_length * _unit_size +
+                       sizeof(uint64_t));
        }
 }
 
@@ -98,14 +101,12 @@ void LogicSnapshot::append_payload_to_mipmap()
        if (m0.length == prev_length)
                return;
 
-       reallocate_mip_map(m0);
+       reallocate_mipmap_level(m0);
 
        dest_ptr = (uint8_t*)m0.data + prev_length * _unit_size;
 
        // Iterate through the samples to populate the first level mipmap
-       accumulator = 0;
-       diff_counter = MipMapScaleFactor;
-       const uint8_t *end_src_ptr = (uint8_t*)_data +
+       const uint8_t *const end_src_ptr = (uint8_t*)_data +
                m0.length * _unit_size * MipMapScaleFactor;
        for (src_ptr = (uint8_t*)_data +
                prev_length * _unit_size * MipMapScaleFactor;
@@ -140,12 +141,12 @@ void LogicSnapshot::append_payload_to_mipmap()
                if (m.length == prev_length)
                        break;
 
-               reallocate_mip_map(m);
+               reallocate_mipmap_level(m);
 
                // Subsample the level lower level
                src_ptr = (uint8_t*)ml.data +
                        _unit_size * prev_length * MipMapScaleFactor;
-               const uint8_t *end_dest_ptr =
+               const uint8_t *const end_dest_ptr =
                        (uint8_t*)m.data + _unit_size * m.length;
                for (dest_ptr = (uint8_t*)m.data +
                        _unit_size * prev_length;
@@ -204,7 +205,10 @@ void LogicSnapshot::get_subsampled_edges(
        {
                //----- Continue to search -----//
                level = min_level;
-               fast_forward = true;
+
+               // We cannot fast-forward if there is no mip-map data at
+               // at the minimum level.
+               fast_forward = (_mip_map[level].data != NULL);
 
                if (min_length < MipMapScaleFactor)
                {
@@ -241,7 +245,8 @@ void LogicSnapshot::get_subsampled_edges(
                        // We can fast forward only if there was no change
                        const bool sample =
                                (get_sample(index) & sig_mask) != 0;
-                       fast_forward = last_sample == sample;
+                       if (last_sample != sample)
+                               fast_forward = false;
                }
 
                if (fast_forward) {