• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "display_auto_brightness.h"
17 
18 #include "display_param_helper.h"
19 
20 namespace OHOS {
21 namespace DisplayPowerMgr {
22 const float DisplayAutoBrightness::LUX_MIN = 0.0;
23 const float DisplayAutoBrightness::LUX_MAX = 10000.0;
24 const uint32_t DisplayAutoBrightness::BRIGHTNESS_MIN = DisplayParamHelper::GetMinBrightness();
25 const uint32_t DisplayAutoBrightness::BRIGHTNESS_MAX = DisplayParamHelper::GetMaxBrightness();
26 const float DisplayAutoBrightness::TRANSFORM_NODE_LUX_START = 0.0;
27 const float DisplayAutoBrightness::TRANSFORM_NODE_LUX_FIRST = 100.0;
28 const float DisplayAutoBrightness::TRANSFORM_NODE_LUX_SECOND = 500.0;
29 // 0.47 is the ratio of brightness value 120 to 255
30 const float DisplayAutoBrightness::TRANSFORM_NODE_BRIGHTNESS_FIRST_PER = 0.47;
31 // 0.86 is the ratio of brightness value 220 to 255
32 const float DisplayAutoBrightness::TRANSFORM_NODE_BRIGHTNESS_SECOND_PER = 0.86;
33 const uint32_t DisplayAutoBrightness::TRANSFORM_NODE_BRIGHTNESS_FIRST = static_cast<uint32_t>(BRIGHTNESS_MIN +
34     TRANSFORM_NODE_BRIGHTNESS_FIRST_PER * (BRIGHTNESS_MAX - BRIGHTNESS_MIN));
35 const uint32_t DisplayAutoBrightness::TRANSFORM_NODE_BRIGHTNESS_SECOND = static_cast<uint32_t>(BRIGHTNESS_MIN +
36     TRANSFORM_NODE_BRIGHTNESS_SECOND_PER * (BRIGHTNESS_MAX - BRIGHTNESS_MIN));
37 
38 const DisplayAutoBrightness::TransformNode DisplayAutoBrightness::TRANSFORM_NODE_TABLE[TRANSFORM_NODE_TYPE_END] = {
39     {TRANSFORM_NODE_LUX_START, BRIGHTNESS_MIN},
40     {TRANSFORM_NODE_LUX_FIRST, TRANSFORM_NODE_BRIGHTNESS_FIRST},
41     {TRANSFORM_NODE_LUX_SECOND, TRANSFORM_NODE_BRIGHTNESS_SECOND},
42     {LUX_MAX, BRIGHTNESS_MAX},
43 };
44 
CalculateAutoBrightness(float scalar)45 uint32_t DisplayAutoBrightness::CalculateAutoBrightness(float scalar)
46 {
47     uint32_t brightness = BRIGHTNESS_MAX;
48     if (scalar >= LUX_MAX) {
49         return brightness;
50     }
51     for (uint8_t count = 1; count < TRANSFORM_NODE_TYPE_END; count++) {
52         auto lastNode = TRANSFORM_NODE_TABLE[count - 1];
53         auto curNode = TRANSFORM_NODE_TABLE[count];
54         if (lastNode.lux <= scalar && scalar < curNode.lux) {
55             brightness = static_cast<uint32_t>(lastNode.brightness + (scalar - lastNode.lux) *
56                 ((curNode.brightness - lastNode.brightness) / (curNode.lux - lastNode.lux)));
57             return brightness;
58         }
59     }
60     return brightness;
61 }
62 } // namespace PowerMgr
63 } // namespace OHOS