• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * x3a_stats_pool.cpp -  3a stats pool
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 "x3a_stats_pool.h"
22 
23 #define XCAM_3A_STATS_DEFAULT_BIT_DEPTH 8
24 
25 namespace XCam {
26 
X3aStatsData(XCam3AStats * data)27 X3aStatsData::X3aStatsData (XCam3AStats *data)
28     : _data (data)
29 {
30     XCAM_ASSERT (_data);
31 }
32 
~X3aStatsData()33 X3aStatsData::~X3aStatsData ()
34 {
35     if (_data)
36         xcam_free (_data);
37 }
38 
39 uint8_t *
map()40 X3aStatsData::map ()
41 {
42     return (uint8_t*)(intptr_t)(_data);
43 }
44 
45 bool
unmap()46 X3aStatsData::unmap ()
47 {
48     return true;
49 }
50 
X3aStats(const SmartPtr<X3aStatsData> & data)51 X3aStats::X3aStats (const SmartPtr<X3aStatsData> &data)
52     : BufferProxy (SmartPtr<BufferData>(data))
53 {
54 }
55 
56 
57 XCam3AStats *
get_stats()58 X3aStats::get_stats ()
59 {
60     SmartPtr<BufferData> data = get_buffer_data ();
61     SmartPtr<X3aStatsData> stats = data.dynamic_cast_ptr<X3aStatsData> ();
62 
63     XCAM_FAIL_RETURN(
64         WARNING,
65         stats.ptr(),
66         NULL,
67         "X3aStats get_stats failed with NULL");
68     return stats->get_stats ();
69 }
70 
X3aStatsPool()71 X3aStatsPool::X3aStatsPool ()
72     : _bit_depth (XCAM_3A_STATS_DEFAULT_BIT_DEPTH)
73 {
74 }
75 
76 void
set_stats_info(const XCam3AStatsInfo & info)77 X3aStatsPool::set_stats_info (const XCam3AStatsInfo &info)
78 {
79     _stats_info = info;
80 }
81 
82 bool
fixate_video_info(VideoBufferInfo & info)83 X3aStatsPool::fixate_video_info (VideoBufferInfo &info)
84 {
85     const uint32_t grid = 16;
86 
87     _stats_info.aligned_width = (info.width + grid - 1) / grid;
88     _stats_info.aligned_height = (info.height + grid - 1) / grid;
89 
90     _stats_info.width = info.width / grid;
91     _stats_info.height = info.height / grid;
92     _stats_info.grid_pixel_size = grid;
93     _stats_info.bit_depth = _bit_depth;
94     _stats_info.histogram_bins = (1 << _bit_depth);
95     return true;
96 }
97 
98 SmartPtr<BufferData>
allocate_data(const VideoBufferInfo & buffer_info)99 X3aStatsPool::allocate_data (const VideoBufferInfo &buffer_info)
100 {
101     XCAM_UNUSED (buffer_info);
102 
103     XCam3AStats *stats = NULL;
104     stats =
105         (XCam3AStats *) xcam_malloc0 (
106             sizeof (XCam3AStats) +
107             sizeof (XCamHistogram) * _stats_info.histogram_bins +
108             sizeof (uint32_t) * _stats_info.histogram_bins +
109             sizeof (XCamGridStat) * _stats_info.aligned_width * _stats_info.aligned_height);
110     XCAM_ASSERT (stats);
111     stats->info = _stats_info;
112     stats->hist_rgb = (XCamHistogram *) (stats->stats +
113                                          _stats_info.aligned_width * _stats_info.aligned_height);
114     stats->hist_y = (uint32_t *) (stats->hist_rgb + _stats_info.histogram_bins);
115     return new X3aStatsData (stats);
116 }
117 
118 SmartPtr<BufferProxy>
create_buffer_from_data(SmartPtr<BufferData> & data)119 X3aStatsPool::create_buffer_from_data (SmartPtr<BufferData> &data)
120 {
121     SmartPtr<X3aStatsData> stats_data = data.dynamic_cast_ptr<X3aStatsData> ();
122     XCAM_ASSERT (stats_data.ptr ());
123 
124     return new X3aStats (stats_data);
125 }
126 
127 };
128