• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #define LOG_NDEBUG 0
17 
18 #define LOG_TAG "AutoLockTest"
19 #include <utils/Log.h>
20 #include <utils/Timers.h>
21 #include <cmath>
22 #include <string>
23 
24 #include "vec2.h"
25 #include "vec3.h"
26 #include "autolocktest.h"
27 
28 const float kOverExposure = 230.f;
29 const float kEqThreshold = 0.05f;
30 // Processes the color checker values and compare the two values from
31 // the same individual test.
processData()32 void AutoLockTest::processData() {
33     ALOGV("Start Processing Auto Lock Test Data!");
34 
35     int numTests = mCheckerColors.size() / 2;
36     mNumPatches = 0;
37 
38     if (numTests > 0) {
39         mNumPatches = mCheckerColors[0].size();
40     }
41 
42     for (int i = 0; i < numTests; ++i) {
43         mComparisonResults.push_back(
44                 IsBrighterThan((&mCheckerColors[i * 2]),
45                                (&mCheckerColors[i * 2 + 1])));
46         mComparisonResults.push_back(
47                 IsEquivalentTo((&mCheckerColors[i * 2]),
48                                (&mCheckerColors[i * 2 + 1])));
49     }
50 }
51 
52 // Compares whether one array of gray color patches is brighter than
53 // another one.
IsBrighterThan(const std::vector<Vec3f> * colorCheckers1,const std::vector<Vec3f> * colorCheckers2) const54 bool AutoLockTest::IsBrighterThan(
55         const std::vector<Vec3f>* colorCheckers1,
56         const std::vector<Vec3f>* colorCheckers2) const {
57     float meanRatio = 0.f;
58     int meanNumCount = 0;
59 
60     for (int i = 0; i < mNumPatches; ++i) {
61         float luminance1 = (*colorCheckers1)[i].convertToLuminance();
62         float luminance2 = (*colorCheckers2)[i].convertToLuminance();
63 
64         // Consider a 5% raise as a considerably large increase.
65         if ((luminance1 < kOverExposure) && (luminance2 != 0.f)) {
66             meanRatio += luminance1 / luminance2;
67             ++meanNumCount;
68         }
69     }
70     meanRatio = meanRatio / meanNumCount;
71 
72     return (meanRatio > 1 + kEqThreshold);
73 }
74 
75 // Compares whether one array of gray color patches is within a small range
76 // of the other one to be considered equivalent.
IsEquivalentTo(const std::vector<Vec3f> * colorCheckers1,const std::vector<Vec3f> * colorCheckers2) const77 bool AutoLockTest::IsEquivalentTo(
78         const std::vector<Vec3f>* colorCheckers1,
79         const std::vector<Vec3f>* colorCheckers2) const {
80     float meanRatio = 0.f;
81     int meanNumCount = 0;
82 
83     for (int i = 0; i < mNumPatches; ++i) {
84         float luminance1 = (*colorCheckers1)[i].convertToLuminance();
85         float luminance2 = (*colorCheckers2)[i].convertToLuminance();
86         ALOGV("Luma_1 and Luma_2 is %f, %f", luminance1, luminance2);
87 
88         if ((luminance1 < kOverExposure) && (luminance2 < kOverExposure)) {
89               meanRatio += luminance2 / luminance1;
90               ++meanNumCount;
91         }
92     }
93     meanRatio = meanRatio / meanNumCount;
94 
95     return ((meanRatio >= 1 - kEqThreshold) && (meanRatio <= 1 + kEqThreshold));
96 }
97 
clearData()98 void AutoLockTest::clearData() {
99     mCheckerColors.clear();
100     mComparisonResults.clear();
101 }
102