blob: a749a83f40217e8b62019a559964019b02d54dfc [file] [log] [blame]
Wind Yuan75564b12015-01-15 06:51:15 -05001/*
2 * sensor_descriptor.h - sensor descriptor
3 *
4 * Copyright (c) 2015 Intel Corporation
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 * Author: Wind Yuan <feng.yuan@intel.com>
19 */
20
21#include "sensor_descriptor.h"
22#include <math.h>
23
24namespace XCam {
25
26SensorDescriptor::SensorDescriptor ()
27{
28 xcam_mem_clear (&_sensor_data);
29}
30
31SensorDescriptor::~SensorDescriptor ()
32{
33}
34
35bool
36SensorDescriptor::is_ready ()
37{
38 return (_sensor_data.line_length_pck > 0);
39}
40
41void
42SensorDescriptor::set_sensor_data (struct atomisp_sensor_mode_data &data)
43{
44 _sensor_data = data;
45}
46
47bool
48SensorDescriptor::exposure_time_to_integration (
49 int32_t exposure_time, uint32_t &coarse_time, uint32_t &fine_time)
50{
51 if (exposure_time < 0 || !is_ready ())
52 return false;
53
54 uint32_t pixel_periods = ((uint64_t)exposure_time) * _sensor_data.vt_pix_clk_freq_mhz / XCAM_SECONDS_2_TIMESTAMP (1);
55
56 coarse_time = pixel_periods / _sensor_data.line_length_pck;
57 fine_time = pixel_periods % _sensor_data.line_length_pck;
58 return true;
59}
60
61bool
62SensorDescriptor::exposure_integration_to_time (
63 uint32_t coarse_time, uint32_t fine_time, int32_t &exposure_time)
64{
65 if (!is_ready ())
66 return false;
67
68 uint64_t pixel_periods = coarse_time * _sensor_data.line_length_pck + fine_time;
69 exposure_time = pixel_periods * XCAM_SECONDS_2_TIMESTAMP(1) / _sensor_data.vt_pix_clk_freq_mhz;
70 return true;
71}
72
73bool
74SensorDescriptor::exposure_gain_to_code (
75 double analog_gain, double digital_gain,
76 int32_t &analog_code, int32_t &digital_code)
77{
78 XCAM_ASSERT (digital_gain == 1.0);
79 double db = log10 (analog_gain * digital_gain) * 20;
80 if (db > 48)
81 db = 48;
82 analog_code = (uint32_t) (db * 160.0 / 48);
83 digital_code = 0;
84 return true;
85}
86
87bool
88SensorDescriptor::exposure_code_to_gain (
89 int32_t analog_code, int32_t digital_code,
90 double &analog_gain, double &digital_gain)
91{
92 double db = analog_code * 48.0 / 160.0;
93 analog_gain = pow (10.0, db / 20.0);
94 digital_gain = 1.0;
95
96 return true;
97}
98
99};