From: Joel Holdsworth Date: Sun, 16 Sep 2012 09:34:31 +0000 (+0100) Subject: Added LogicDataSnapshot::get_subsample helper function X-Git-Tag: pulseview-0.1.0~300 X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=commitdiff_plain;h=b2bcbe51febaef24a211ed19bc61408c8fbdc399 Added LogicDataSnapshot::get_subsample helper function --- diff --git a/logicdatasnapshot.cpp b/logicdatasnapshot.cpp index 5301abf5..9cc7819f 100644 --- a/logicdatasnapshot.cpp +++ b/logicdatasnapshot.cpp @@ -233,8 +233,7 @@ void LogicDataSnapshot::get_subsampled_edges( // Check if we reached the last block at this level, // or if there was a change in this block if(offset >= _mip_map[level].length || - (*(uint64_t*)((uint8_t*)_mip_map[level].data + - _unit_size * offset) & sig_mask)) + (get_subsample(level, offset) & sig_mask)) break; if((offset & ~(~0 << MipMapScalePower)) == 0) @@ -268,8 +267,7 @@ void LogicDataSnapshot::get_subsampled_edges( // Check if we reached the last block at this level, // or if there was a change in this block if(offset >= _mip_map[level].length || - (*(uint64_t*)((uint8_t*)_mip_map[level].data + - _unit_size * offset) & sig_mask)) + (get_subsample(level, offset) & sig_mask)) { // Zoom in unless we reached the minimum zoom if(level == min_level) @@ -323,6 +321,14 @@ void LogicDataSnapshot::get_subsampled_edges( get_sample(end) & sig_mask)); } +uint64_t LogicDataSnapshot::get_subsample(int level, uint64_t offset) const +{ + assert(level >= 0); + assert(_mip_map[level].data); + return *(uint64_t*)((uint8_t*)_mip_map[level].data + + _unit_size * offset); +} + int64_t LogicDataSnapshot::pow2_ceil(int64_t x, unsigned int power) { const int64_t p = 1 << power; diff --git a/logicdatasnapshot.h b/logicdatasnapshot.h index de0f4732..cb56b222 100644 --- a/logicdatasnapshot.h +++ b/logicdatasnapshot.h @@ -79,6 +79,7 @@ public: float min_length, int sig_index); private: + uint64_t get_subsample(int level, uint64_t offset) const; static int64_t pow2_ceil(int64_t x, unsigned int power); diff --git a/test/logicdatasnapshot.cpp b/test/logicdatasnapshot.cpp index 66232cd6..bd9aabfd 100644 --- a/test/logicdatasnapshot.cpp +++ b/test/logicdatasnapshot.cpp @@ -187,14 +187,14 @@ BOOST_AUTO_TEST_CASE(LargeData) BOOST_TEST_MESSAGE("Testing mip_map[0].data[" << i << "]"); const uint8_t sample = (uint8_t)((i*16) >> 8); - BOOST_CHECK_EQUAL(*((uint8_t*)s._mip_map[0].data + i++), + BOOST_CHECK_EQUAL(s.get_subsample(0, i++) & 0xFF, prev_sample ^ sample); prev_sample = sample; for(int j = 1; i < s._mip_map[0].length && j < 16; j++) { BOOST_TEST_MESSAGE("Testing mip_map[0].data[" << i << "]"); - BOOST_CHECK_EQUAL(*((uint8_t*)s._mip_map[0].data + i++), 0); + BOOST_CHECK_EQUAL(s.get_subsample(0, i++) & 0xFF, 0); } } @@ -213,8 +213,7 @@ BOOST_AUTO_TEST_CASE(LargeData) const uint8_t expected = sample ^ prev_sample; prev_sample = i; - BOOST_CHECK_EQUAL(*((uint8_t*)s._mip_map[1].data + i), - expected); + BOOST_CHECK_EQUAL(s.get_subsample(1, i) & 0xFF, expected); } // Check mip map level 2 @@ -232,8 +231,7 @@ BOOST_AUTO_TEST_CASE(LargeData) const uint8_t expected = (sample ^ prev_sample) | 0x0F; prev_sample = sample; - BOOST_CHECK_EQUAL(*((uint8_t*)s._mip_map[2].data + i), - expected); + BOOST_CHECK_EQUAL(s.get_subsample(2, i) & 0xFF, expected); } // Check mip map level 3