Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 91913565 authored by Emilian Peev's avatar Emilian Peev
Browse files

Camera: Fix off-by-one error during clamping in distortion mapper

The (right, bottom) coordinates of any input rectangles are
exclusive.

Bug: 111885753
Test: Camera CTS,
adb shell /data/nativetest64/cameraservice_test/cameraservice_test
--gtest_filter=DistortionMapperTest.*
Change-Id: Ied956bd154256a10fc4c81d27c93b0ba2e33044d
parent d02904c6
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -312,8 +312,8 @@ status_t DistortionMapper::mapRawRectToCorrected(int32_t *rects, int rectCount,
        int32_t coords[4] = {
            rects[i],
            rects[i + 1],
            rects[i] + rects[i + 2],
            rects[i + 1] + rects[i + 3]
            rects[i] + rects[i + 2] - 1,
            rects[i + 1] + rects[i + 3] - 1
        };

        mapRawToCorrected(coords, 2, clamp, simple);
@@ -321,8 +321,8 @@ status_t DistortionMapper::mapRawRectToCorrected(int32_t *rects, int rectCount,
        // Map back to (l, t, width, height)
        rects[i] = coords[0];
        rects[i + 1] = coords[1];
        rects[i + 2] = coords[2] - coords[0];
        rects[i + 3] = coords[3] - coords[1];
        rects[i + 2] = coords[2] - coords[0] + 1;
        rects[i + 3] = coords[3] - coords[1] + 1;
    }

    return OK;
@@ -400,8 +400,8 @@ status_t DistortionMapper::mapCorrectedRectToRaw(int32_t *rects, int rectCount,
        int32_t coords[4] = {
            rects[i],
            rects[i + 1],
            rects[i] + rects[i + 2],
            rects[i + 1] + rects[i + 3]
            rects[i] + rects[i + 2] - 1,
            rects[i + 1] + rects[i + 3] - 1
        };

        mapCorrectedToRaw(coords, 2, clamp, simple);
@@ -409,8 +409,8 @@ status_t DistortionMapper::mapCorrectedRectToRaw(int32_t *rects, int rectCount,
        // Map back to (l, t, width, height)
        rects[i] = coords[0];
        rects[i + 1] = coords[1];
        rects[i + 2] = coords[2] - coords[0];
        rects[i + 3] = coords[3] - coords[1];
        rects[i + 2] = coords[2] - coords[0] + 1;
        rects[i + 3] = coords[3] - coords[1] + 1;
    }

    return OK;
+24 −0
Original line number Diff line number Diff line
@@ -167,6 +167,30 @@ TEST(DistortionMapperTest, IdentityTransform) {
    }
}

TEST(DistortionMapperTest, ClampConsistency) {
    status_t res;

    std::array<int32_t, 4> activeArray = {0, 0, 4032, 3024};
    DistortionMapper m;
    setupTestMapper(&m, identityDistortion, testICal, /*activeArray*/ activeArray.data(),
            /*preCorrectionActiveArray*/ activeArray.data());

    auto rectsOrig = activeArray;
    res = m.mapCorrectedRectToRaw(activeArray.data(), 1, /*clamp*/true, /*simple*/ true);
    ASSERT_EQ(res, OK);

    for (size_t i = 0; i < activeArray.size(); i++) {
        EXPECT_EQ(activeArray[i], rectsOrig[i]);
    }

    res = m.mapRawRectToCorrected(activeArray.data(), 1, /*clamp*/true, /*simple*/ true);
    ASSERT_EQ(res, OK);

    for (size_t i = 0; i < activeArray.size(); i++) {
        EXPECT_EQ(activeArray[i], rectsOrig[i]);
    }
}

TEST(DistortionMapperTest, SimpleTransform) {
    status_t res;