Home | History | Annotate | Download | only in hybrid
      1 /*
      2  * aiq_wrapper.cpp - aiq wrapper:
      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: Jia Meng <jia.meng (at) intel.com>
     19  */
     20 
     21 #include <base/xcam_3a_description.h>
     22 #include <xcam_std.h>
     23 
     24 using namespace XCam;
     25 
     26 #define CONTEXT_CAST(context)  ((XCam3AHybridContext*)(context))
     27 
     28 class XCam3AHybridContext
     29 {
     30 public:
     31     XCam3AHybridContext ();
     32     ~XCam3AHybridContext ();
     33 
     34 private:
     35     XCAM_DEAD_COPY (XCam3AHybridContext);
     36 
     37 };
     38 
     39 XCam3AHybridContext::XCam3AHybridContext ()
     40 {
     41 }
     42 
     43 XCam3AHybridContext::~XCam3AHybridContext ()
     44 {
     45 }
     46 
     47 static XCamReturn
     48 xcam_create_context (XCam3AContext **context)
     49 {
     50     XCAM_ASSERT (context);
     51     XCam3AHybridContext *ctx = new XCam3AHybridContext ();
     52     *context = ((XCam3AContext*)(ctx));
     53     return XCAM_RETURN_NO_ERROR;
     54 }
     55 
     56 static XCamReturn
     57 xcam_destroy_context (XCam3AContext *context)
     58 {
     59     XCam3AHybridContext *ctx = CONTEXT_CAST (context);
     60     delete ctx;
     61     return XCAM_RETURN_NO_ERROR;
     62 }
     63 
     64 // configure customized 3a analyzer with width/height/framerate
     65 static XCamReturn
     66 xcam_configure_3a (XCam3AContext *context, uint32_t width, uint32_t height, double framerate)
     67 {
     68     XCAM_UNUSED (context);
     69     XCAM_UNUSED (width);
     70     XCAM_UNUSED (height);
     71     XCAM_UNUSED (framerate);
     72 
     73     return XCAM_RETURN_NO_ERROR;
     74 }
     75 
     76 // set 3a stats to customized 3a analyzer for subsequent usage
     77 static XCamReturn
     78 xcam_set_3a_stats (XCam3AContext *context, XCam3AStats *stats, int64_t timestamp)
     79 {
     80     XCAM_UNUSED (context);
     81     XCAM_UNUSED (timestamp);
     82 
     83     XCam3AStatsInfo info = stats->info;
     84     for (uint32_t i = 0; i < info.height; ++i)
     85         for (uint32_t j = 0; j < info.width; ++j) {
     86             XCAM_LOG_DEBUG ("%d %d %d %d %d %d %d %d",
     87                             stats->stats[i * info.aligned_width + j].avg_y,
     88                             stats->stats[i * info.aligned_width + j].avg_gr,
     89                             stats->stats[i * info.aligned_width + j].avg_r,
     90                             stats->stats[i * info.aligned_width + j].avg_b,
     91                             stats->stats[i * info.aligned_width + j].avg_gb,
     92                             stats->stats[i * info.aligned_width + j].valid_wb_count,
     93                             stats->stats[i * info.aligned_width + j].f_value1,
     94                             stats->stats[i * info.aligned_width + j].f_value2);
     95         }
     96 
     97     return XCAM_RETURN_NO_ERROR;
     98 }
     99 
    100 // refer to xcam_params.h for common parameters
    101 static XCamReturn
    102 xcam_update_common_params (XCam3AContext *context, XCamCommonParam *params)
    103 {
    104     XCAM_UNUSED (context);
    105     XCAM_UNUSED (params);
    106 
    107     return XCAM_RETURN_NO_ERROR;
    108 }
    109 
    110 // customized awb algorithm should be added here
    111 static XCamReturn
    112 xcam_analyze_awb (XCam3AContext *context, XCamAwbParam *params)
    113 {
    114     XCAM_UNUSED (context);
    115     XCAM_UNUSED (params);
    116 
    117     return XCAM_RETURN_NO_ERROR;
    118 }
    119 
    120 // customized ae algorithm should be added here
    121 static XCamReturn
    122 xcam_analyze_ae (XCam3AContext *context, XCamAeParam *params)
    123 {
    124     XCAM_UNUSED (context);
    125     XCAM_UNUSED (params);
    126 
    127     return XCAM_RETURN_NO_ERROR;
    128 }
    129 
    130 // customized af is unsupported now
    131 static XCamReturn
    132 xcam_analyze_af (XCam3AContext *context, XCamAfParam *params)
    133 {
    134     XCAM_UNUSED (context);
    135     XCAM_UNUSED (params);
    136 
    137     return XCAM_RETURN_NO_ERROR;
    138 }
    139 
    140 // combine ae/awb analyze results and set to framework
    141 // only support XCam3aResultExposure and XCam3aResultWhiteBalance now
    142 static XCamReturn
    143 xcam_combine_analyze_results (XCam3AContext *context, XCam3aResultHead *results[], uint32_t *res_count)
    144 {
    145     XCAM_UNUSED (context);
    146 
    147     uint32_t result_count = 2;
    148     static XCam3aResultHead *res_array[XCAM_3A_MAX_RESULT_COUNT];
    149     xcam_mem_clear (res_array);
    150 
    151     for (uint32_t i = 0; i < result_count; ++i) {
    152         results[i] = res_array[i];
    153     }
    154     *res_count = result_count;
    155 
    156     XCam3aResultExposure *exposure = xcam_malloc0_type (XCam3aResultExposure);
    157     XCAM_ASSERT (exposure);
    158     exposure->head.type = XCAM_3A_RESULT_EXPOSURE;
    159     exposure->head.process_type = XCAM_IMAGE_PROCESS_ALWAYS;
    160     exposure->head.version = XCAM_VERSION;
    161     exposure->exposure_time = 9986; // 9.986ms
    162     exposure->analog_gain = 10;
    163     results[0] = (XCam3aResultHead *)exposure;
    164 
    165     XCam3aResultWhiteBalance *wb = xcam_malloc0_type (XCam3aResultWhiteBalance);
    166     XCAM_ASSERT (wb);
    167     wb->head.type = XCAM_3A_RESULT_WHITE_BALANCE;
    168     wb->head.process_type = XCAM_IMAGE_PROCESS_ALWAYS;
    169     wb->head.version = XCAM_VERSION;
    170     wb->gr_gain = 1.0;
    171     wb->r_gain = 1.6453;
    172     wb->b_gain = 2.0645;
    173     wb->gb_gain = 1.0;
    174     results[1] = (XCam3aResultHead *)wb;
    175 
    176     return XCAM_RETURN_NO_ERROR;
    177 }
    178 
    179 static void
    180 xcam_free_results (XCam3aResultHead *results[], uint32_t res_count)
    181 {
    182     for (uint32_t i = 0; i < res_count; ++i) {
    183         if (results[i])
    184             xcam_free (results[i]);
    185     }
    186 }
    187 
    188 XCAM_BEGIN_DECLARE
    189 
    190 XCam3ADescription xcam_3a_desciption = {
    191     XCAM_VERSION,
    192     sizeof (XCam3ADescription),
    193     xcam_create_context,
    194     xcam_destroy_context,
    195     xcam_configure_3a,
    196     xcam_set_3a_stats,
    197     xcam_update_common_params,
    198     xcam_analyze_awb,
    199     xcam_analyze_ae,
    200     xcam_analyze_af,
    201     xcam_combine_analyze_results,
    202     xcam_free_results
    203 };
    204 
    205 XCAM_END_DECLARE
    206 
    207