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

Commit c3462a1b authored by Yin-Chia Yeh's avatar Yin-Chia Yeh Committed by Eino-Ville Talvala
Browse files

Camera: fix metering region conversion

Zero weight regions have no actual effect. Skip them.
Also clamp the correction result to be within active
array.

Test: GCA smoke test
Bug: 109766306
Change-Id: I24640ffb564f30dcbc14cf8c97f8100c0bad2640
parent cc073aac
Loading
Loading
Loading
Loading
+33 −1
Original line number Original line Diff line number Diff line
@@ -18,6 +18,7 @@
#define ATRACE_TAG ATRACE_TAG_CAMERA
#define ATRACE_TAG ATRACE_TAG_CAMERA
//#define LOG_NDEBUG 0
//#define LOG_NDEBUG 0


#include <algorithm>
#include <cmath>
#include <cmath>


#include "device3/DistortionMapper.h"
#include "device3/DistortionMapper.h"
@@ -81,6 +82,10 @@ status_t DistortionMapper::setupStaticInfo(const CameraMetadata &deviceInfo) {
    mArrayWidth = array.data.i32[2];
    mArrayWidth = array.data.i32[2];
    mArrayHeight = array.data.i32[3];
    mArrayHeight = array.data.i32[3];


    array = deviceInfo.find(ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE);
    mActiveWidth = array.data.i32[2];
    mActiveHeight = array.data.i32[3];

    return updateCalibration(deviceInfo);
    return updateCalibration(deviceInfo);
}
}


@@ -102,8 +107,21 @@ status_t DistortionMapper::correctCaptureRequest(CameraMetadata *request) {
        for (auto region : kMeteringRegionsToCorrect) {
        for (auto region : kMeteringRegionsToCorrect) {
            e = request->find(region);
            e = request->find(region);
            for (size_t j = 0; j < e.count; j += 5) {
            for (size_t j = 0; j < e.count; j += 5) {
                int32_t weight = e.data.i32[j + 4];
                if (weight == 0) {
                    continue;
                }
                res = mapCorrectedToRaw(e.data.i32 + j, 2);
                res = mapCorrectedToRaw(e.data.i32 + j, 2);
                if (res != OK) return res;
                if (res != OK) return res;
                for (size_t k = 0; k < 4; k+=2) {
                    int32_t& x = e.data.i32[j + k];
                    int32_t& y = e.data.i32[j + k + 1];
                    // Clamp to within active array
                    x = std::max(0, x);
                    x = std::min(mActiveWidth - 1, x);
                    y = std::max(0, y);
                    y = std::min(mActiveHeight - 1, y);
                }
            }
            }
        }
        }
        for (auto rect : kRequestRectsToCorrect) {
        for (auto rect : kRequestRectsToCorrect) {
@@ -134,8 +152,21 @@ status_t DistortionMapper::correctCaptureResult(CameraMetadata *result) {
        for (auto region : kMeteringRegionsToCorrect) {
        for (auto region : kMeteringRegionsToCorrect) {
            e = result->find(region);
            e = result->find(region);
            for (size_t j = 0; j < e.count; j += 5) {
            for (size_t j = 0; j < e.count; j += 5) {
                int32_t weight = e.data.i32[j + 4];
                if (weight == 0) {
                    continue;
                }
                res = mapRawToCorrected(e.data.i32 + j, 2);
                res = mapRawToCorrected(e.data.i32 + j, 2);
                if (res != OK) return res;
                if (res != OK) return res;
                for (size_t k = 0; k < 4; k+=2) {
                    int32_t& x = e.data.i32[j + k];
                    int32_t& y = e.data.i32[j + k + 1];
                    // Clamp to within active array
                    x = std::max(0, x);
                    x = std::min(mActiveWidth - 1, x);
                    y = std::max(0, y);
                    y = std::min(mActiveHeight - 1, y);
                }
            }
            }
        }
        }
        for (auto rect : kResultRectsToCorrect) {
        for (auto rect : kResultRectsToCorrect) {
@@ -212,7 +243,8 @@ status_t DistortionMapper::mapRawToCorrected(int32_t *coordPairs, int coordCount
    for (int i = 0; i < coordCount * 2; i += 2) {
    for (int i = 0; i < coordCount * 2; i += 2) {
        const GridQuad *quad = findEnclosingQuad(coordPairs + i, mDistortedGrid);
        const GridQuad *quad = findEnclosingQuad(coordPairs + i, mDistortedGrid);
        if (quad == nullptr) {
        if (quad == nullptr) {
            ALOGE("Raw to corrected mapping failure: No quad found");
            ALOGE("Raw to corrected mapping failure: No quad found for (%d, %d)",
                    *(coordPairs + i), *(coordPairs + i + 1));
            return INVALID_OPERATION;
            return INVALID_OPERATION;
        }
        }
        ALOGV("src xy: %d, %d, enclosing quad: (%f, %f), (%f, %f), (%f, %f), (%f, %f)",
        ALOGV("src xy: %d, %d, enclosing quad: (%f, %f), (%f, %f), (%f, %f), (%f, %f)",
+2 −0
Original line number Original line Diff line number Diff line
@@ -169,6 +169,8 @@ class DistortionMapper {


    // pre-correction active array dimensions
    // pre-correction active array dimensions
    int mArrayWidth, mArrayHeight;
    int mArrayWidth, mArrayHeight;
    // active array dimensions
    int mActiveWidth, mActiveHeight;


    std::vector<GridQuad> mCorrectedGrid;
    std::vector<GridQuad> mCorrectedGrid;
    std::vector<GridQuad> mDistortedGrid;
    std::vector<GridQuad> mDistortedGrid;