GXDE Bernese
Loading...
Searching...
No Matches
channel_sum.h
1/*
2 * Copyright (C) 2026 CharOfString <root@charofstring.cc>
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the Free
6 * Software Foundation, either version 3 of the License, or (at your option)
7 * any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18#ifndef IMAGE_UTILS_CHANNEL_SUM_CHANNEL_SUM_H_
19#define IMAGE_UTILS_CHANNEL_SUM_CHANNEL_SUM_H_
20
21#include "QColor"
22#include "QtGlobal"
23
24namespace bernese {
25namespace image_utils {
26namespace internal {
27
28// Sum premultiplied channels together to preserve color at transparent edges.
29struct ChannelSum {
30 qint64 red = 0;
31 qint64 green = 0;
32 qint64 blue = 0;
33 qint64 alpha = 0;
34
41 void Accumulate(QRgb pixel, int weight) {
42 red += weight * qRed(pixel);
43 green += weight * qGreen(pixel);
44 blue += weight * qBlue(pixel);
45 alpha += weight * qAlpha(pixel);
46 }
47
54 QRgb Average(int sample_count) const {
55 return qRgba(red / sample_count, green / sample_count, blue / sample_count,
56 alpha / sample_count);
57 }
58};
59
60} // namespace internal
61} // namespace image_utils
62} // namespace bernese
63
64#endif // IMAGE_UTILS_CHANNEL_SUM_CHANNEL_SUM_H_
void Accumulate(QRgb pixel, int weight)
Add or subtract one premultiplied pixel from the running sum.
Definition channel_sum.h:41
QRgb Average(int sample_count) const
Compute the averaged premultiplied pixel.
Definition channel_sum.h:54