Warning, file /office/calligra/libs/pigment/KoCompositeColorTransformation.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002  *  Copyright (c) 2015 Dmitry Kazakov <dimula73@gmail.com>
0003  *
0004  *  This program is free software; you can redistribute it and/or modify
0005  *  it under the terms of the GNU General Public License as published by
0006  *  the Free Software Foundation; either version 2 of the License, or
0007  *  (at your option) any later version.
0008  *
0009  *  This program is distributed in the hope that it will be useful,
0010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012  *  GNU General Public License for more details.
0013  *
0014  *  You should have received a copy of the GNU General Public License
0015  *  along with this program; if not, write to the Free Software
0016  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0017  */
0018 
0019 #include "KoCompositeColorTransformation.h"
0020 
0021 #include <QVector>
0022 
0023 
0024 struct Q_DECL_HIDDEN KoCompositeColorTransformation::Private
0025 {
0026     ~Private() {
0027         qDeleteAll(transformations);
0028     }
0029 
0030     QVector<KoColorTransformation*> transformations;
0031 };
0032 
0033 
0034 KoCompositeColorTransformation::KoCompositeColorTransformation(Mode mode)
0035     : m_d(new Private)
0036 {
0037     Q_ASSERT_X(mode == INPLACE, "KoCompositeColorTransformation", "BUFFERED mode is not implemented yet!");
0038     Q_UNUSED(mode)
0039 }
0040 
0041 KoCompositeColorTransformation::~KoCompositeColorTransformation()
0042 {
0043 }
0044 
0045 void KoCompositeColorTransformation::appendTransform(KoColorTransformation *transform)
0046 {
0047     if (transform) {
0048         m_d->transformations.append(transform);
0049     }
0050 }
0051 
0052 void KoCompositeColorTransformation::transform(const quint8 *src, quint8 *dst, qint32 nPixels) const
0053 {
0054     QVector<KoColorTransformation*>::const_iterator begin = m_d->transformations.constBegin();
0055     QVector<KoColorTransformation*>::const_iterator it = begin;
0056     QVector<KoColorTransformation*>::const_iterator end = m_d->transformations.constEnd();
0057 
0058     for (; it != end; ++it) {
0059         if (it == begin) {
0060             (*it)->transform(src, dst, nPixels);
0061         } else {
0062             (*it)->transform(dst, dst, nPixels);
0063         }
0064     }
0065 }
0066 
0067 KoColorTransformation* KoCompositeColorTransformation::createOptimizedCompositeTransform(const QVector<KoColorTransformation*> transforms)
0068 {
0069     KoColorTransformation *finalTransform = 0;
0070 
0071     int numValidTransforms = 0;
0072     foreach (KoColorTransformation *t, transforms) {
0073         numValidTransforms += bool(t);
0074     }
0075 
0076     if (numValidTransforms > 1) {
0077         KoCompositeColorTransformation *compositeTransform =
0078             new KoCompositeColorTransformation(
0079                 KoCompositeColorTransformation::INPLACE);
0080 
0081         foreach (KoColorTransformation *t, transforms) {
0082             if (t) {
0083                 compositeTransform->appendTransform(t);
0084             }
0085         }
0086 
0087         finalTransform = compositeTransform;
0088 
0089     } else if (numValidTransforms == 1) {
0090         foreach (KoColorTransformation *t, transforms) {
0091             if (t) {
0092                 finalTransform = t;
0093                 break;
0094             }
0095         }
0096     }
0097 
0098     return finalTransform;
0099 }