Skip to content

Commit 47de551

Browse files
committed
RenderedTarget: Fix index out of range in colorAtScratchPoint()
1 parent 476f02e commit 47de551

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/renderedtarget.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,8 +591,8 @@ QRgb RenderedTarget::colorAtScratchPoint(double x, double y) const
591591

592592
// Translate the coordinates
593593
QPointF point = mapFromScratchToLocal(QPointF(x, y));
594-
x = point.x();
595-
y = point.y();
594+
x = std::floor(point.x());
595+
y = std::floor(point.y());
596596

597597
const double width = m_cpuTexture.width();
598598
const double height = m_cpuTexture.height();

test/renderedtarget/renderedtarget_test.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -402,19 +402,19 @@ TEST_F(RenderedTargetTest, CpuRendering)
402402

403403
ASSERT_EQ(target.colorAtScratchPoint(-227.5, 164), 0); // [0, 1]
404404
ASSERT_EQ(target.colorAtScratchPoint(-226.5, 164), 4278190335); // [1, 1]
405-
ASSERT_EQ(target.colorAtScratchPoint(-226.1, 163.75), 4278255615); // [1.4, 1.25]
405+
ASSERT_EQ(target.colorAtScratchPoint(-226.1, 163.75), 4278190335); // [1.4, 1.25]
406406
ASSERT_EQ(target.colorAtScratchPoint(-225.5, 164), 4294902015); // [2, 1]
407407
ASSERT_EQ(target.colorAtScratchPoint(-224.5, 164), 4294934656); // [3, 1]
408408

409409
ASSERT_EQ(target.colorAtScratchPoint(-226.5, 163), 4278190208); // [1, 2]
410410
ASSERT_EQ(target.colorAtScratchPoint(-225.5, 163), 0); // [2, 2]
411411
ASSERT_EQ(target.colorAtScratchPoint(-224.5, 163), 2505545047); // [3, 2]
412-
ASSERT_EQ(target.colorAtScratchPoint(-224, 162.9), 9764864); // [3.5, 2.1]
412+
ASSERT_EQ(target.colorAtScratchPoint(-224, 162.9), 2505545047); // [3.5, 2.1]
413413

414-
ASSERT_EQ(target.colorAtScratchPoint(-226.5, 162), 4286578816); // [1, 3]
415-
ASSERT_EQ(target.colorAtScratchPoint(-225.5, 162), 4286611711); // [2, 3]
416-
ASSERT_EQ(target.colorAtScratchPoint(-224.5, 162), 4286611456); // [3, 3]
417-
ASSERT_EQ(target.colorAtScratchPoint(-224.2, 161.5), 0); // [3.3, 3.5]
414+
ASSERT_EQ(target.colorAtScratchPoint(-226.5, 162), 4286578816); // [1, 3]
415+
ASSERT_EQ(target.colorAtScratchPoint(-225.5, 162), 4286611711); // [2, 3]
416+
ASSERT_EQ(target.colorAtScratchPoint(-224.5, 162), 4286611456); // [3, 3]
417+
ASSERT_EQ(target.colorAtScratchPoint(-224.2, 161.5), 4286611456); // [3.3, 3.5]
418418

419419
// Cleanup
420420
context.doneCurrent();

0 commit comments

Comments
 (0)