2
* Copyright (c) 2009 Cyrille Berger <cberger@cberger.net>
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation; either
7
* version 2 of the License, or (at your option) any later version.
9
* This library is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Lesser General Public License for more details.
14
* You should have received a copy of the GNU Lesser General Public License
15
* along with this library; see the file COPYING.LIB. If not, write to
16
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
* Boston, MA 02110-1301, USA.
20
#ifndef _KO_CTL_ACCUMULATOR_H_
21
#define _KO_CTL_ACCUMULATOR_H_
23
#include "KoColorSpaceMaths.h"
25
class KoCtlAccumulator
28
virtual ~KoCtlAccumulator();
29
virtual void mix(const quint8* _pixel, double _weight) = 0;
30
virtual void reset() = 0;
31
virtual void affect(quint8* _pixel, double _alpha) = 0;
32
virtual void affect(quint8* _pixel, qint32 factor, qint32 offset) = 0;
35
template<typename _type_>
36
class KoCtlAccumulatorImpl : public KoCtlAccumulator
39
KoCtlAccumulatorImpl(int _pos) : m_pos(_pos) {}
40
virtual ~KoCtlAccumulatorImpl() {}
41
inline const _type_* ptr(const quint8* _pixel) {
42
return reinterpret_cast<const _type_*>(_pixel + m_pos);
44
inline _type_* ptr(quint8* _pixel) {
45
return reinterpret_cast<_type_*>(_pixel + m_pos);
47
virtual void mix(const quint8* _pixel, double _weight) {
48
m_value += *ptr(_pixel) * _weight;
50
virtual void reset() {
53
virtual void affect(quint8* _pixel, double _alpha) {
54
typename KoColorSpaceMathsTraits< _type_ >::compositetype v = m_value * _alpha;
56
if (v > KoColorSpaceMathsTraits<_type_>::max) {
57
v = KoColorSpaceMathsTraits<_type_>::max;
59
if (v < KoColorSpaceMathsTraits<_type_>::min) {
60
v = KoColorSpaceMathsTraits<_type_>::min;
64
virtual void affect(quint8* _pixel, qint32 factor, qint32 offset) {
65
typename KoColorSpaceMathsTraits< _type_ >::compositetype v = m_value / factor + offset;
67
if (v > KoColorSpaceMathsTraits<_type_>::max) {
68
v = KoColorSpaceMathsTraits<_type_>::max;
70
if (v < KoColorSpaceMathsTraits<_type_>::min) {
71
v = KoColorSpaceMathsTraits<_type_>::min;
77
typename KoColorSpaceMathsTraits< _type_ >::compositetype m_value;