blob: eefda834b8d8c6f98b60b08e9ad05c1a80592c7c [file] [log] [blame]
Wind Yuanf17e93a2015-04-14 18:45:38 +08001/*
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 return true;
92}
93
94SmartPtr<BufferData>
95X3aStatsPool::allocate_data (const VideoBufferInfo &buffer_info)
96{
Wind Yuan2f9c6c52015-04-30 16:53:28 +080097 XCAM_UNUSED (buffer_info);
98
Wind Yuanf17e93a2015-04-14 18:45:38 +080099 XCam3AStats *stats = NULL;
100 stats =
101 (XCam3AStats *) xcam_malloc0 (
102 sizeof (XCam3AStats) +
103 sizeof (XCamGridStat) * _stats_info.aligned_width * _stats_info.aligned_height);
104 stats->info = _stats_info;
105 return new X3aStatsData (stats);
106}
107
108SmartPtr<BufferProxy>
109X3aStatsPool::create_buffer_from_data (SmartPtr<BufferData> &data)
110{
111 SmartPtr<X3aStatsData> stats_data = data.dynamic_cast_ptr<X3aStatsData> ();
112 XCAM_ASSERT (stats_data.ptr ());
113
114 return new X3aStats (stats_data);
115}
116
117};