]> sigrok.org Git - pulseview.git/blobdiff - pv/data/logicsegment.cpp
Unify get_samples() semantics for AnalogSegment and LogicSegment
[pulseview.git] / pv / data / logicsegment.cpp
index 3e18b85ef4143bb399c5dd1dcff2fb7e6375d7ed..dab6b91dee295194f343115c7f2cdeecec5657e6 100644 (file)
@@ -14,8 +14,7 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
 #include <extdef.h>
@@ -153,10 +152,9 @@ void LogicSegment::append_payload(shared_ptr<Logic> logic)
        append_payload_to_mipmap();
 }
 
-void LogicSegment::get_samples(uint8_t *const data,
-       int64_t start_sample, int64_t end_sample) const
+const uint8_t* LogicSegment::get_samples(int64_t start_sample,
+       int64_t end_sample) const
 {
-       assert(data);
        assert(start_sample >= 0);
        assert(start_sample <= (int64_t)sample_count_);
        assert(end_sample >= 0);
@@ -165,8 +163,10 @@ void LogicSegment::get_samples(uint8_t *const data,
 
        lock_guard<recursive_mutex> lock(mutex_);
 
+       uint8_t* data = new uint8_t[end_sample - start_sample];
        const size_t size = (end_sample - start_sample) * unit_size_;
-       memcpy(data, (const uint8_t*)data_.data() + start_sample * unit_size_, size);
+       memcpy(data, (uint8_t*)data_.data() + start_sample * unit_size_, size);
+       return data;
 }
 
 void LogicSegment::reallocate_mipmap_level(MipMapLevel &m)
@@ -308,7 +308,7 @@ void LogicSegment::get_subsampled_edges(
                                pow2_ceil(index, MipMapScalePower));
 
                        for (; index < final_index &&
-                                       (index & ~(~0 << MipMapScalePower)) != 0;
+                                       (index & ~((uint64_t)(~0) << MipMapScalePower)) != 0;
                                        index++) {
                                const bool sample =
                                        (get_sample(index) & sig_mask) != 0;
@@ -358,7 +358,7 @@ void LogicSegment::get_subsampled_edges(
                                                sig_mask))
                                        break;
 
-                               if ((offset & ~(~0 << MipMapScalePower)) == 0) {
+                               if ((offset & ~((uint64_t)(~0) << MipMapScalePower)) == 0) {
                                        // If we are now at the beginning of a
                                        // higher level mip-map block ascend one
                                        // level