Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_incremental_average.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2015 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7#ifndef __KIS_INCREMENTAL_AVERAGE_H
8#define __KIS_INCREMENTAL_AVERAGE_H
9
10#include <kis_debug.h>
11#include <QVector>
12
13
15{
16public:
18 : m_size(size),
19 m_index(-1),
20 m_sum(0),
21 m_values(size)
22 {
23 }
24
25 inline int pushThrough(int value) {
26 if (m_index < 0) {
27 for (int i = 0; i < m_size; i++) {
28 m_values[i] = value;
29 }
30 m_index = 0;
31 m_sum = 3 * value;
32 return value;
33 }
34
35 int oldValue = m_values[m_index];
37
38 m_sum += value - oldValue;
39
40 if (++m_index >= m_size) {
41 m_index = 0;
42 }
43
44 return m_sum / m_size;
45 }
46
47private:
48 int m_size;
50 int m_sum;
52};
53
54#endif /* __KIS_INCREMENTAL_AVERAGE_H */
float value(const T *src, size_t ch)