Warning, file /office/calligra/libs/pigment/KoFallBackColorTransformation.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) 2007 Cyrille Berger <cberger@cberger.net> 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Lesser General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2.1 of the License, or (at your option) any later version. 0008 * 0009 * This library 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 GNU 0012 * Lesser General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU Lesser General Public License 0015 * along with this library; see the file COPYING.LIB. If not, write to 0016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #include "KoFallBackColorTransformation.h" 0021 0022 #include "KoColorConversionTransformation.h" 0023 #include "KoColorSpace.h" 0024 #include "KoColorTransformation.h" 0025 #include "KoColorConversionCache.h" 0026 #include "KoColorSpaceRegistry.h" 0027 0028 #include "DebugPigment.h" 0029 0030 struct Q_DECL_HIDDEN KoFallBackColorTransformation::Private { 0031 const KoColorSpace* fallBackColorSpace; 0032 KoCachedColorConversionTransformation* csToFallBackCache; 0033 KoCachedColorConversionTransformation* fallBackToCsCache; 0034 const KoColorConversionTransformation* csToFallBack; 0035 const KoColorConversionTransformation* fallBackToCs; 0036 KoColorTransformation* colorTransformation; 0037 mutable quint8* buff; 0038 mutable qint32 buffSize; 0039 }; 0040 0041 KoFallBackColorTransformation::KoFallBackColorTransformation(const KoColorSpace* _cs, const KoColorSpace* _fallBackCS, KoColorTransformation* _transfo) : d(new Private) 0042 { 0043 d->fallBackColorSpace = _fallBackCS; 0044 d->csToFallBackCache = new KoCachedColorConversionTransformation(KoColorSpaceRegistry::instance()->colorConversionCache()->cachedConverter(_cs, _fallBackCS, KoColorConversionTransformation::internalRenderingIntent(), KoColorConversionTransformation::internalConversionFlags())); 0045 d->csToFallBack = d->csToFallBackCache->transformation(); 0046 d->fallBackToCsCache = new KoCachedColorConversionTransformation(KoColorSpaceRegistry::instance()->colorConversionCache()->cachedConverter(_fallBackCS, _cs, KoColorConversionTransformation::internalRenderingIntent(), KoColorConversionTransformation::internalConversionFlags())); 0047 d->fallBackToCs = d->fallBackToCsCache->transformation(); 0048 d->colorTransformation = _transfo; 0049 d->buff = 0; 0050 d->buffSize = 0; 0051 } 0052 0053 KoFallBackColorTransformation::KoFallBackColorTransformation(KoColorConversionTransformation* _csToFallBack, KoColorConversionTransformation* _fallBackToCs, KoColorTransformation* _transfo) : d(new Private) 0054 { 0055 Q_ASSERT(*_csToFallBack->srcColorSpace() == *_fallBackToCs->dstColorSpace()); 0056 Q_ASSERT(*_fallBackToCs->srcColorSpace() == *_csToFallBack->dstColorSpace()); 0057 d->fallBackColorSpace = _fallBackToCs->srcColorSpace(); 0058 d->csToFallBack = _csToFallBack; 0059 d->fallBackToCs = _fallBackToCs; 0060 d->csToFallBackCache = 0; 0061 d->fallBackToCsCache = 0; 0062 d->colorTransformation = _transfo; 0063 d->buff = 0; 0064 d->buffSize = 0; 0065 } 0066 0067 KoFallBackColorTransformation::~KoFallBackColorTransformation() 0068 { 0069 if (d->csToFallBackCache) { 0070 delete d->csToFallBackCache; 0071 } else { 0072 delete d->csToFallBack; 0073 } 0074 if (d->csToFallBackCache) { 0075 delete d->fallBackToCsCache; 0076 } else { 0077 delete d->fallBackToCs; 0078 } 0079 delete d->colorTransformation; 0080 delete[] d->buff; 0081 delete d; 0082 } 0083 0084 void KoFallBackColorTransformation::transform(const quint8 *src, quint8 *dst, qint32 nPixels) const 0085 { 0086 if (d->buffSize < nPixels) { // Expand the buffer if needed 0087 d->buffSize = nPixels; 0088 delete[] d->buff; 0089 d->buff = new quint8[ d->buffSize * d->fallBackColorSpace->pixelSize()]; 0090 } 0091 d->csToFallBack->transform(src, d->buff, nPixels); 0092 d->colorTransformation->transform(d->buff, d->buff, nPixels); 0093 d->fallBackToCs->transform(d->buff, dst, nPixels); 0094 } 0095 0096 QList<QString> KoFallBackColorTransformation::parameters() const 0097 { 0098 return d->colorTransformation->parameters(); 0099 } 0100 0101 int KoFallBackColorTransformation::parameterId(const QString& name) const 0102 { 0103 return d->colorTransformation->parameterId(name); 0104 } 0105 0106 void KoFallBackColorTransformation::setParameter(int id, const QVariant& parameter) 0107 { 0108 d->colorTransformation->setParameter(id, parameter); 0109 }