lin
2025-08-14 dae8bad597b6607a449b32bf76c523423f7720ed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
 * x3a_stats_pool.cpp -  3a stats pool
 *
 *  Copyright (c) 2015 Intel Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Author: Wind Yuan <feng.yuan@intel.com>
 */
 
#include "x3a_stats_pool.h"
 
#define XCAM_3A_STATS_DEFAULT_BIT_DEPTH 8
 
namespace XCam {
 
X3aStatsData::X3aStatsData (XCam3AStats *data)
    : _data (data)
{
    XCAM_ASSERT (_data);
}
 
X3aStatsData::~X3aStatsData ()
{
    if (_data)
        xcam_free (_data);
}
 
uint8_t *
X3aStatsData::map ()
{
    return (uint8_t*)(intptr_t)(_data);
}
 
bool
X3aStatsData::unmap ()
{
    return true;
}
 
X3aStats::X3aStats (const SmartPtr<X3aStatsData> &data)
    : BufferProxy (SmartPtr<BufferData>(data))
{
}
 
 
XCam3AStats *
X3aStats::get_stats ()
{
    SmartPtr<BufferData> data = get_buffer_data ();
    SmartPtr<X3aStatsData> stats = data.dynamic_cast_ptr<X3aStatsData> ();
 
    XCAM_FAIL_RETURN(
        WARNING,
        stats.ptr(),
        NULL,
        "X3aStats get_stats failed with NULL");
    return stats->get_stats ();
}
 
X3aStatsPool::X3aStatsPool ()
    : _bit_depth (XCAM_3A_STATS_DEFAULT_BIT_DEPTH)
{
}
 
void
X3aStatsPool::set_stats_info (const XCam3AStatsInfo &info)
{
    _stats_info = info;
}
 
bool
X3aStatsPool::fixate_video_info (VideoBufferInfo &info)
{
    const uint32_t grid = 16;
 
    _stats_info.aligned_width = (info.width + grid - 1) / grid;
    _stats_info.aligned_height = (info.height + grid - 1) / grid;
 
    _stats_info.width = info.width / grid;
    _stats_info.height = info.height / grid;
    _stats_info.grid_pixel_size = grid;
    _stats_info.bit_depth = _bit_depth;
    _stats_info.histogram_bins = (1 << _bit_depth);
    return true;
}
 
SmartPtr<BufferData>
X3aStatsPool::allocate_data (const VideoBufferInfo &buffer_info)
{
    XCAM_UNUSED (buffer_info);
 
    XCam3AStats *stats = NULL;
    stats =
        (XCam3AStats *) xcam_malloc0 (
            sizeof (XCam3AStats) +
            sizeof (XCamHistogram) * _stats_info.histogram_bins +
            sizeof (uint32_t) * _stats_info.histogram_bins +
            sizeof (XCamGridStat) * _stats_info.aligned_width * _stats_info.aligned_height);
    XCAM_ASSERT (stats);
    stats->info = _stats_info;
    stats->hist_rgb = (XCamHistogram *) (stats->stats +
                                         _stats_info.aligned_width * _stats_info.aligned_height);
    stats->hist_y = (uint32_t *) (stats->hist_rgb + _stats_info.histogram_bins);
    return new X3aStatsData (stats);
}
 
SmartPtr<BufferProxy>
X3aStatsPool::create_buffer_from_data (SmartPtr<BufferData> &data)
{
    SmartPtr<X3aStatsData> stats_data = data.dynamic_cast_ptr<X3aStatsData> ();
    XCAM_ASSERT (stats_data.ptr ());
 
    return new X3aStats (stats_data);
}
 
};