Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 1 | /* |
| 2 | * isp_image_processor.cpp - isp image processor |
| 3 | * |
| 4 | * Copyright (c) 2014-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 "isp_image_processor.h" |
| 22 | #include "x3a_isp_config.h" |
| 23 | #include "isp_controller.h" |
| 24 | #include "isp_config_translator.h" |
| 25 | |
| 26 | namespace XCam { |
| 27 | |
| 28 | IspImageProcessor::IspImageProcessor (SmartPtr<IspController> &controller) |
| 29 | : ImageProcessor ("IspImageProcessor") |
| 30 | , _controller (controller) |
| 31 | , _3a_config (new X3aIspConfig) |
| 32 | { |
| 33 | _sensor = new SensorDescriptor; |
| 34 | _translator = new IspConfigTranslator (_sensor); |
| 35 | XCAM_LOG_DEBUG ("IspImageProcessor construction"); |
| 36 | } |
| 37 | |
| 38 | IspImageProcessor::~IspImageProcessor () |
| 39 | { |
| 40 | XCAM_LOG_DEBUG ("~IspImageProcessor destruction"); |
| 41 | } |
| 42 | |
| 43 | XCamReturn |
| 44 | IspImageProcessor::process_buffer(SmartPtr<VideoBuffer> &input, SmartPtr<VideoBuffer> &output) |
| 45 | { |
| 46 | output = input; |
| 47 | return XCAM_RETURN_NO_ERROR; |
| 48 | } |
| 49 | |
| 50 | bool |
| 51 | IspImageProcessor::can_process_result (SmartPtr<X3aResult> &result) |
| 52 | { |
| 53 | XCAM_ASSERT (result.ptr()); |
| 54 | switch (result->get_type()) { |
| 55 | case X3aIspConfig::IspExposureParameters: |
| 56 | case X3aIspConfig::IspAllParameters: |
| 57 | case XCAM_3A_RESULT_WHITE_BALANCE: |
| 58 | case XCAM_3A_RESULT_EXPOSURE: |
| 59 | case XCAM_3A_RESULT_BLACK_LEVEL: |
| 60 | case XCAM_3A_RESULT_YUV2RGB_MATRIX: |
| 61 | case XCAM_3A_RESULT_RGB2YUV_MATRIX: |
| 62 | return true; |
| 63 | default: |
| 64 | return false; |
| 65 | } |
| 66 | |
| 67 | return false; |
| 68 | } |
| 69 | |
| 70 | XCamReturn |
| 71 | IspImageProcessor::apply_3a_results (X3aResultList &results) |
| 72 | { |
| 73 | XCamReturn ret = XCAM_RETURN_NO_ERROR; |
| 74 | |
| 75 | if (results.empty()) |
| 76 | return XCAM_RETURN_ERROR_PARAM; |
| 77 | |
| 78 | // activate sensor to make translator work |
| 79 | if (!_sensor->is_ready()) { |
| 80 | struct atomisp_sensor_mode_data sensor_data; |
| 81 | xcam_mem_clear (&sensor_data); |
| 82 | if (_controller->get_sensor_mode_data(sensor_data) != XCAM_RETURN_NO_ERROR) { |
| 83 | XCAM_LOG_WARNING ("ispimageprocessor initiliaze sensor failed"); |
| 84 | } else |
| 85 | _sensor->set_sensor_data (sensor_data); |
| 86 | XCAM_ASSERT (_sensor->is_ready()); |
| 87 | } |
| 88 | |
| 89 | if ((ret = merge_results (results)) != XCAM_RETURN_NO_ERROR) { |
| 90 | XCAM_LOG_WARNING ("merge 3a result to isp config failed"); |
| 91 | return XCAM_RETURN_ERROR_UNKNOWN; |
| 92 | } |
| 93 | |
| 94 | if ((ret = apply_exposure_result (results)) != XCAM_RETURN_NO_ERROR) { |
| 95 | XCAM_LOG_WARNING ("set 3a exposure to sensor failed"); |
| 96 | } |
| 97 | |
| 98 | // check _3a_config |
| 99 | XCAM_ASSERT (_3a_config.ptr()); |
| 100 | XCAM_ASSERT (_controller.ptr()); |
| 101 | ret = _controller->set_3a_config (_3a_config.ptr()); |
| 102 | if (ret != XCAM_RETURN_NO_ERROR) { |
| 103 | XCAM_LOG_WARNING ("set 3a config to isp failed"); |
| 104 | } |
| 105 | _3a_config->clear (); |
| 106 | return ret; |
| 107 | } |
| 108 | |
| 109 | XCamReturn |
| 110 | IspImageProcessor::apply_3a_result (SmartPtr<X3aResult> &result) |
| 111 | { |
| 112 | XCamReturn ret = XCAM_RETURN_NO_ERROR; |
| 113 | |
| 114 | X3aResultList results; |
| 115 | results.push_back (result); |
| 116 | ret = apply_3a_results (results); |
| 117 | return ret; |
| 118 | } |
| 119 | |
| 120 | XCamReturn |
| 121 | IspImageProcessor::merge_results (X3aResultList &results) |
| 122 | { |
| 123 | if (results.empty()) |
| 124 | return XCAM_RETURN_ERROR_PARAM; |
| 125 | |
| 126 | for (X3aResultList::iterator iter = results.begin (); |
| 127 | iter != results.end ();) |
| 128 | { |
| 129 | SmartPtr<X3aResult> &x3a_result = *iter; |
| 130 | if (_3a_config->attach (x3a_result, _translator.ptr())) { |
| 131 | x3a_result->set_done (true); |
| 132 | results.erase (iter++); |
| 133 | } else |
| 134 | ++iter; |
| 135 | } |
| 136 | return XCAM_RETURN_NO_ERROR; |
| 137 | } |
| 138 | |
| 139 | XCamReturn |
| 140 | IspImageProcessor::apply_exposure_result (X3aResultList &results) |
| 141 | { |
| 142 | XCamReturn ret = XCAM_RETURN_NO_ERROR; |
| 143 | |
| 144 | for (X3aResultList::iterator iter = results.begin (); |
| 145 | iter != results.end ();) |
| 146 | { |
| 147 | if ((*iter)->get_type() == X3aIspConfig::IspExposureParameters) { |
Wind Yuan | be689bf | 2015-02-11 13:48:29 +0800 | [diff] [blame] | 148 | SmartPtr<X3aIspExposureResult> res = (*iter).dynamic_cast_ptr<X3aIspExposureResult> (); |
| 149 | if (!res.ptr () || |
| 150 | ((ret = _controller->set_3a_exposure (res.ptr ())) != XCAM_RETURN_NO_ERROR)) { |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 151 | XCAM_LOG_WARNING ("set 3a exposure to sensor failed"); |
| 152 | } |
| 153 | res->set_done (true); |
| 154 | results.erase (iter++); |
| 155 | } else if ((*iter)->get_type() == XCAM_3A_RESULT_EXPOSURE) { |
Wind Yuan | be689bf | 2015-02-11 13:48:29 +0800 | [diff] [blame] | 156 | SmartPtr<X3aExposureResult> res = (*iter).dynamic_cast_ptr<X3aExposureResult> (); |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 157 | struct atomisp_exposure isp_exposure; |
| 158 | xcam_mem_clear (&isp_exposure); |
Wind Yuan | be689bf | 2015-02-11 13:48:29 +0800 | [diff] [blame] | 159 | XCAM_ASSERT (res.ptr ()); |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 160 | ret = _translator->translate_exposure (res->get_standard_result (), isp_exposure); |
| 161 | if (ret != XCAM_RETURN_NO_ERROR) { |
| 162 | XCAM_LOG_WARNING ("translate 3a exposure to sensor failed"); |
| 163 | } |
| 164 | if ((ret = _controller->set_3a_exposure (isp_exposure)) != XCAM_RETURN_NO_ERROR) { |
| 165 | XCAM_LOG_WARNING ("set 3a exposure to sensor failed"); |
| 166 | } |
| 167 | res->set_done (true); |
| 168 | results.erase (iter++); |
| 169 | } else |
| 170 | ++iter; |
| 171 | } |
| 172 | return XCAM_RETURN_NO_ERROR; |
| 173 | } |
| 174 | |
| 175 | }; |