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

Commit 8a177430 authored by Austin Borger's avatar Austin Borger
Browse files

RotateAndCropMapper - reverse rotation direction.

Based on an end-to-end test of the RotateAndCropMapper, the rotation
is being applied in the wrong direction. After swapping 270 and 90
degree rotations, the output is as expected.

Bug: 261775770
Test: Ran face detection on app with all rotations
Change-Id: I209e360918d9e48abf2372527602b2b454e3b88a
parent 3560b7e9
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -142,13 +142,13 @@ status_t RotateAndCropMapper::updateCaptureRequest(CameraMetadata *request) {
                   ch :                 // pillarbox or 1:1, full height
                   cw / mRotateAspect;  // letterbox, not full height
        switch (rotateMode) {
            case ANDROID_SCALER_ROTATE_AND_CROP_90:
            case ANDROID_SCALER_ROTATE_AND_CROP_270:
                transformMat[1] = -rw / ch; // +y -> -x
                transformMat[2] =  rh / cw; // +x -> +y
                xShift = (cw + rw) / 2; // left edge of crop to right edge of rotated
                yShift = (ch - rh) / 2; // top edge of crop to top edge of rotated
                break;
            case ANDROID_SCALER_ROTATE_AND_CROP_270:
            case ANDROID_SCALER_ROTATE_AND_CROP_90:
                transformMat[1] =  rw / ch; // +y -> +x
                transformMat[2] = -rh / cw; // +x -> -y
                xShift = (cw - rw) / 2; // left edge of crop to left edge of rotated
@@ -271,13 +271,13 @@ status_t RotateAndCropMapper::updateCaptureResult(CameraMetadata *result) {
        rx = cx + (cw - rw) / 2;
        ry = cy + (ch - rh) / 2;
        switch (rotateMode) {
            case ANDROID_SCALER_ROTATE_AND_CROP_90:
            case ANDROID_SCALER_ROTATE_AND_CROP_270:
                transformMat[1] =  ch / rw; // +y -> +x
                transformMat[2] = -cw / rh; // +x -> -y
                xShift = -(cw - rw) / 2; // left edge of rotated to left edge of cropped
                yShift = ry - cy + ch;   // top edge of rotated to bottom edge of cropped
                break;
            case ANDROID_SCALER_ROTATE_AND_CROP_270:
            case ANDROID_SCALER_ROTATE_AND_CROP_90:
                transformMat[1] = -ch / rw; // +y -> -x
                transformMat[2] =  cw / rh; // +x -> +y
                xShift = (cw + rw) / 2; // left edge of rotated to left edge of cropped
+7 −7
Original line number Diff line number Diff line
@@ -195,6 +195,7 @@ TEST(RotationMapperTest, Transform90) {

    // Round-trip results can't be exact since we've gone from a large int range -> small int range
    // and back, leading to quantization. For 4/3 aspect ratio, no more than +-1 error expected

    e = result.find(ANDROID_CONTROL_AE_REGIONS);
    EXPECT_EQUAL_WITHIN_N(full_region, e.data.i32, 1, "Round-tripped AE region isn't right");

@@ -209,11 +210,11 @@ TEST(RotationMapperTest, Transform90) {
    EXPECT_EQUAL_WITHIN_N(full_face, e.data.i32, 1, "App-side face rectangle isn't right");

    auto full_landmarks = std::vector<int32_t> {
        full_crop[0], full_crop[1] + full_crop[3],
        full_crop[0] + full_crop[2], full_crop[1],
        full_crop[0] + full_crop[2]/4, full_crop[1] + 3*full_crop[3]/4,
        full_crop[0], full_crop[1] + full_crop[3],
        full_crop[0] + 3*full_crop[2]/4, full_crop[1] + full_crop[3]/4,
        full_crop[0] + full_crop[2]/2, full_crop[1] + full_crop[3]/2,
        full_crop[0] + 3*full_crop[2]/4, full_crop[1] + full_crop[3]/4
        full_crop[0] + full_crop[2]/4, full_crop[1] + 3*full_crop[3]/4
    };
    e = result.find(ANDROID_STATISTICS_FACE_LANDMARKS);
    EXPECT_EQUAL_WITHIN_N(full_landmarks, e.data.i32, 1, "App-side face landmarks aren't right");
@@ -286,7 +287,6 @@ TEST(RotationMapperTest, Transform270) {

    // Round-trip results can't be exact since we've gone from a large int range -> small int range
    // and back, leading to quantization. For 4/3 aspect ratio, no more than +-1 error expected

    e = result.find(ANDROID_CONTROL_AE_REGIONS);
    EXPECT_EQUAL_WITHIN_N(full_region, e.data.i32, 1, "Round-tripped AE region isn't right");

@@ -301,11 +301,11 @@ TEST(RotationMapperTest, Transform270) {
    EXPECT_EQUAL_WITHIN_N(full_face, e.data.i32, 1, "App-side face rectangle isn't right");

    auto full_landmarks = std::vector<int32_t> {
        full_crop[0] + full_crop[2], full_crop[1],
        full_crop[0], full_crop[1] + full_crop[3],
        full_crop[0] + 3*full_crop[2]/4, full_crop[1] + full_crop[3]/4,
        full_crop[0] + full_crop[2], full_crop[1],
        full_crop[0] + full_crop[2]/4, full_crop[1] + 3*full_crop[3]/4,
        full_crop[0] + full_crop[2]/2, full_crop[1] + full_crop[3]/2,
        full_crop[0] + full_crop[2]/4, full_crop[1] + 3*full_crop[3]/4
        full_crop[0] + 3*full_crop[2]/4, full_crop[1] + full_crop[3]/4
    };
    e = result.find(ANDROID_STATISTICS_FACE_LANDMARKS);
    EXPECT_EQUAL_WITHIN_N(full_landmarks, e.data.i32, 1, "App-side face landmarks aren't right");