krita/image
kis_color_transformation_filter.ccGo to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kis_color_transformation_filter.h"
00021
00022 #include <KoColorTransformation.h>
00023 #include <KoProgressUpdater.h>
00024 #include <KoUpdater.h>
00025
00026 #include <kis_iterators_pixel.h>
00027 #include <kis_processing_information.h>
00028 #include <kis_paint_device.h>
00029 #include <kis_selection.h>
00030
00031 #ifndef NDEBUG
00032 #include <QTime>
00033 #endif
00034
00035 typedef QPointer<KoUpdater> KoUpdaterPtr;
00036
00037 KisColorTransformationFilter::KisColorTransformationFilter(const KoID& id, const KoID & category, const QString & entry) : KisFilter(id, category, entry)
00038 {
00039 }
00040
00041 KisColorTransformationFilter::~KisColorTransformationFilter()
00042 {
00043 }
00044
00045 void KisColorTransformationFilter::process(KisConstProcessingInformation srcInfo,
00046 KisProcessingInformation dstInfo,
00047 const QSize& size,
00048 const KisFilterConfiguration* config,
00049 KoUpdater* progressUpdater
00050 ) const
00051 {
00052 const KisPaintDeviceSP src = srcInfo.paintDevice();
00053 KisPaintDeviceSP dst = dstInfo.paintDevice();
00054 QPoint dstTopLeft = dstInfo.topLeft();
00055 QPoint srcTopLeft = srcInfo.topLeft();
00056 Q_UNUSED(config);
00057 Q_ASSERT(!src.isNull());
00058 Q_ASSERT(!dst.isNull());
00059
00060 if (progressUpdater) {
00061 progressUpdater->setRange(0, size.height());
00062 }
00063
00064 const KoColorSpace * cs = src->colorSpace();
00065 KoColorTransformation* colorTransformation = createTransformation(cs, config);
00066 if (!colorTransformation) return;
00067
00068 bool hasSelection = srcInfo.selection();
00069 KisHLineConstIteratorPixel srcIt = src->createHLineConstIterator(srcTopLeft.x(), srcTopLeft.y(), size.width(), srcInfo.selection());
00070 KisHLineIteratorPixel dstIt = dst->createHLineIterator(dstTopLeft.x(), dstTopLeft.y(), size.width(), dstInfo.selection());
00071
00072 for (int row = 0; row < size.height(); ++row) {
00073 while (! srcIt.isDone()) {
00074 int srcItConseq = srcIt.nConseqHPixels();
00075 int dstItConseq = dstIt.nConseqHPixels();
00076 int conseqPixels = qMin(srcItConseq, dstItConseq);
00077
00078 int pixels = 0;
00079 int pixelsSrc = 0;
00080
00081 if (hasSelection) {
00082
00083 const quint8* oldRawData = srcIt.oldRawData();
00084 while (srcIt.isSelected() && pixels < conseqPixels) {
00085 ++pixels;
00086 ++srcIt;
00087 ++pixelsSrc;
00088 }
00089 colorTransformation->transform(oldRawData, dstIt.rawData(), pixels);
00090
00091
00092
00093 while (!srcIt.isSelected() && pixels < conseqPixels) {
00094 ++ pixels;
00095 ++srcIt;
00096 ++pixelsSrc;
00097 }
00098 } else {
00099 pixels = conseqPixels;
00100 colorTransformation->transform(srcIt.oldRawData(), dstIt.rawData(), pixels);
00101 }
00102
00103
00104 srcIt += (pixels - pixelsSrc);
00105 dstIt += pixels;
00106 }
00107 if (progressUpdater) progressUpdater->setValue(row);
00108
00109 srcIt.nextRow();
00110 dstIt.nextRow();
00111 }
00112 delete colorTransformation;
00113
00114
00115 }
|