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