]> sigrok.org Git - pulseview.git/commitdiff
Added LogicDataSnapshot::get_subsample helper function
authorJoel Holdsworth <redacted>
Sun, 16 Sep 2012 09:34:31 +0000 (10:34 +0100)
committerJoel Holdsworth <redacted>
Sun, 16 Sep 2012 10:23:08 +0000 (11:23 +0100)
logicdatasnapshot.cpp
logicdatasnapshot.h
test/logicdatasnapshot.cpp

index 5301abf59d04d6920892a5b6bfaa143ebf04c9ad..9cc7819f2b178a9ba4ca2df2bec128607164da56 100644 (file)
@@ -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 ||
                        // 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)
                                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 ||
                        // 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)
                        {
                                // 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));
 }
 
                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;
 int64_t LogicDataSnapshot::pow2_ceil(int64_t x, unsigned int power)
 {
        const int64_t p = 1 << power;
index de0f4732bf28fb1c949a904b0c0364cb2ef1aaa1..cb56b2226431d3a2e7aad2c9d10608ef37621ae3 100644 (file)
@@ -79,6 +79,7 @@ public:
                float min_length, int sig_index);
 
 private:
                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);
 
 
        static int64_t pow2_ceil(int64_t x, unsigned int power);
 
index 66232cd6975be057bb6f9fa3d1cf7b4e027da037..bd9aabfd493150b06be7cae1b23bba069145ebef 100644 (file)
@@ -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_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 << "]");
                        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;
 
                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
        }
 
        // 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;
 
                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
        }
 
        // Check mip map level 3