• 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 "ExposureCompensationTest"
19 #include <utils/Log.h>
20 #include <utils/Timers.h>
21 #include <cmath>
22 #include <string>
23 #include <stdio.h>
24 
25 #include "vec2.h"
26 #include "vec3.h"
27 #include "exposurecompensationtest.h"
28 
29 const float GAMMA_CORRECTION = 2.2f;
processData()30 void ExposureCompensationTest::processData() {
31     ALOGV("Start Processing Exposure Compensation Test Data!");
32     clearDebugImage();
33 
34     if (mDebugText != NULL) {
35         delete mDebugText;
36         mDebugText = NULL;
37     }
38 
39     int numTests = mExposureValues.size();
40     int numPatches = mCheckerColors[0].size();
41     ALOGV("Processing %d tests with %d patches", numTests, numPatches);
42 
43     mDebugText = new char[320 * numTests];
44     mDebugText[0] = 0;
45     char* debugText = new char[50];
46 
47     Vec3i red(255, 0, 0);
48     Vec3i green(0, 255, 0);
49     Vec3i blue(0, 0, 255);
50 
51     float minExposure = -3.0f;
52     float scale = 9.0f;
53     for (int i = 0; i < numTests; ++i) {
54         snprintf(debugText, 50, "Exposure is %f \n", mExposureValues[i]);
55         strcat(mDebugText, debugText);
56         for (int j = 0; j < numPatches; ++j) {
57             int exposureRed = static_cast<int>((
58                 log(static_cast<float>(mReferenceColors[j].r()))
59                 / log(2.0f) * GAMMA_CORRECTION +
60                 mExposureValues[i] - minExposure) * scale);
61             int exposureGreen = static_cast<int>((
62                 log(static_cast<float>(mReferenceColors[j].g()))
63                 / log(2.0f) * GAMMA_CORRECTION +
64                 mExposureValues[i] - minExposure) * scale);
65             int exposureBlue = static_cast<int>((
66                 log(static_cast<float>(mReferenceColors[j].b()))
67                 / log(2.0f) * GAMMA_CORRECTION +
68                 mExposureValues[i] - minExposure) * scale);
69 
70             snprintf(debugText, 50, "%d %f %d %f %d %f \n",
71                     exposureRed, mCheckerColors[i][j].r(),
72                     exposureGreen, mCheckerColors[i][j].g(),
73                     exposureBlue, mCheckerColors[i][j].b());
74 
75             ALOGV("%s", debugText);
76             strcat(mDebugText, debugText);
77 
78             drawPoint(200 - exposureRed, mCheckerColors[i][j].r(), red);
79             drawPoint(200 - exposureGreen, mCheckerColors[i][j].g(), green);
80             drawPoint(200 - exposureBlue, mCheckerColors[i][j].b(), blue);
81         }
82     }
83     mExposureValues.clear();
84     mCheckerColors.clear();
85 }
86 
initializeReferenceColors()87 void ExposureCompensationTest::initializeReferenceColors() {
88     mReferenceColors.resize(6);
89 
90     mReferenceColors[0].set(243, 243, 242);
91     mReferenceColors[1].set(200, 200, 200);
92     mReferenceColors[2].set(160, 160, 160);
93     mReferenceColors[3].set(122, 122, 121);
94     mReferenceColors[4].set(85, 85, 85);
95     mReferenceColors[5].set(52, 52, 52);
96 }
97