diff --git a/libs/image/kis_random_sub_accessor.cpp b/libs/image/kis_random_sub_accessor.cpp index 08ae4128cb..9a0dfa87fa 100644 --- a/libs/image/kis_random_sub_accessor.cpp +++ b/libs/image/kis_random_sub_accessor.cpp @@ -1,92 +1,109 @@ /* * This file is part of the KDE project * * Copyright (c) 2006 Cyrille Berger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kis_random_sub_accessor.h" #include #include #include #include #include "kis_paint_device.h" KisRandomSubAccessor::KisRandomSubAccessor(KisPaintDeviceSP device) : m_device(device) , m_currentPoint(0, 0) , m_randomAccessor(device->createRandomConstAccessorNG(0, 0)) { } KisRandomSubAccessor::~KisRandomSubAccessor() { } void KisRandomSubAccessor::sampledOldRawData(quint8* dst) { const quint8* pixels[4]; qint16 weights[4]; - int x = (int)floor(m_currentPoint.x()); - int y = (int)floor(m_currentPoint.y()); + qreal x = m_currentPoint.x(); + qreal y = m_currentPoint.y(); + int xz = qRound(x); + int yz = qRound(y); + double hsub = m_currentPoint.x() - x; - if (hsub < 0.0) hsub = 1.0 + hsub; + if (hsub < 0.0) { + hsub = 1.0 + hsub; + } double vsub = m_currentPoint.y() - y; - if (vsub < 0.0) vsub = 1.0 + vsub; + if (vsub < 0.0) { + vsub = 1.0 + vsub; + } + weights[0] = qRound((1.0 - hsub) * (1.0 - vsub) * 255); - m_randomAccessor->moveTo(x, y); + m_randomAccessor->moveTo(xz, yz); pixels[0] = m_randomAccessor->oldRawData(); weights[1] = qRound((1.0 - vsub) * hsub * 255); - m_randomAccessor->moveTo(x + 1, y); + m_randomAccessor->moveTo(xz + 1, yz); pixels[1] = m_randomAccessor->oldRawData(); weights[2] = qRound(vsub * (1.0 - hsub) * 255); - m_randomAccessor->moveTo(x, y + 1); + m_randomAccessor->moveTo(xz, yz + 1); pixels[2] = m_randomAccessor->oldRawData(); weights[3] = qRound(hsub * vsub * 255); - m_randomAccessor->moveTo(x + 1, y + 1); + m_randomAccessor->moveTo(xz + 1, yz + 1); pixels[3] = m_randomAccessor->oldRawData(); + m_device->colorSpace()->mixColorsOp()->mixColors(pixels, weights, 4, dst); } void KisRandomSubAccessor::sampledRawData(quint8* dst) { const quint8* pixels[4]; qint16 weights[4]; - int x = (int)floor(m_currentPoint.x()); - int y = (int)floor(m_currentPoint.y()); + qreal x = m_currentPoint.x(); + qreal y = m_currentPoint.y(); + int xz = qRound(x); + int yz = qRound(y); + double hsub = m_currentPoint.x() - x; - if (hsub < 0.0) hsub = 1.0 + hsub; + if (hsub < 0.0) { + hsub = 1.0 + hsub; + } double vsub = m_currentPoint.y() - y; - if (vsub < 0.0) vsub = 1.0 + vsub; + if (vsub < 0.0) { + vsub = 1.0 + vsub; + } + weights[0] = qRound((1.0 - hsub) * (1.0 - vsub) * 255); - m_randomAccessor->moveTo(x, y); + m_randomAccessor->moveTo(xz, yz); pixels[0] = m_randomAccessor->rawDataConst(); weights[1] = qRound((1.0 - vsub) * hsub * 255); - m_randomAccessor->moveTo(x + 1, y); + m_randomAccessor->moveTo(xz + 1, yz); pixels[1] = m_randomAccessor->rawDataConst(); weights[2] = qRound(vsub * (1.0 - hsub) * 255); - m_randomAccessor->moveTo(x, y + 1); + m_randomAccessor->moveTo(xz, yz + 1); pixels[2] = m_randomAccessor->rawDataConst(); weights[3] = qRound(hsub * vsub * 255); - m_randomAccessor->moveTo(x + 1, y + 1); + m_randomAccessor->moveTo(xz + 1, yz + 1); pixels[3] = m_randomAccessor->rawDataConst(); m_device->colorSpace()->mixColorsOp()->mixColors(pixels, weights, 4, dst); } diff --git a/libs/image/kis_random_sub_accessor.h b/libs/image/kis_random_sub_accessor.h index 2b3cca8c63..b3b81e1810 100644 --- a/libs/image/kis_random_sub_accessor.h +++ b/libs/image/kis_random_sub_accessor.h @@ -1,62 +1,63 @@ /* * This file is part of the KDE project * * Copyright (c) 2006 Cyrille Berger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KIS_RANDOM_SUB_ACCESSOR_H #define KIS_RANDOM_SUB_ACCESSOR_H #include "kis_random_accessor_ng.h" #include "kis_types.h" #include #include "kis_shared.h" /** * Gives a random access to the sampled subpixels of an image. Use the * moveTo function to select the pixel. And then rawData to access the * value of a pixel. */ class KRITAIMAGE_EXPORT KisRandomSubAccessor : public KisShared { public: KisRandomSubAccessor(KisPaintDeviceSP device); ~KisRandomSubAccessor(); /** * Copy the sampled old value to destination */ void sampledOldRawData(quint8* dst); /** * Copy the sampled value to destination */ void sampledRawData(quint8* dst); - inline void moveTo(double x, double y) { + inline void moveTo(qreal x, qreal y) { m_currentPoint.setX(x); m_currentPoint.setY(y); } inline void moveTo(const QPointF& p) { m_currentPoint = p; } + private: KisPaintDeviceSP m_device; QPointF m_currentPoint; KisRandomConstAccessorSP m_randomAccessor; }; #endif