diff --git a/plugins/generators/screentone/screentonefunctions.cpp b/plugins/generators/screentone/screentonefunctions.cpp index 46bee9f0da..a5c8705bd3 100644 --- a/plugins/generators/screentone/screentonefunctions.cpp +++ b/plugins/generators/screentone/screentonefunctions.cpp @@ -1,197 +1,198 @@ /* * KDE. Krita Project. * * Copyright (c) 2020 Deif Lou * * 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 "screentonefunctions.h" #include #include #include QStringList patternNames() { return QStringList() << i18n("Dots") << i18n("Lines"); } QStringList shapeNames(int pattern) { if (pattern == DotsPattern) { return QStringList() << i18n("Round") << i18n("Ellipse") << i18n("Diamond") << i18n("Square"); } else if (pattern == LinesPattern) { return QStringList() << i18n("Straight") << i18n("Sine Wave") << i18n("Triangular Wave") << i18n("Sawtooth Wave") << i18n("Curtains"); } return QStringList(); } QStringList interpolationNames(int pattern, int shape) { if (pattern == DotsPattern) { if (shape == RoundDotsShape || shape == EllipseDotsShape) { return QStringList() << i18n("Linear") << i18n("Sinusoidal"); } } else if (pattern == LinesPattern) { return QStringList() << i18n("Linear") << i18n("Sinusoidal"); } return QStringList(); } qreal sinFunction(qreal x) { return std::cos(x * M_PI); } qreal triangleFunction(qreal x) { return 1.0 - 2.0 * std::abs(x - std::floor(x + 0.5)); } qreal sawToothFunction(qreal x) { constexpr qreal peakXOffset = 0.9; constexpr qreal peakYOffset = 0.5; x = x - std::floor(x); return (x < peakXOffset ? 1.0 / peakXOffset * x : -1.0 / (1.0 - peakXOffset) * (x - 1.0)) * peakYOffset; } qreal DotsRoundLinearScreentoneFunction::operator()(qreal x, qreal y) const { x = std::abs(x - std::floor(x)) - 0.5; y = std::abs(y - std::floor(y)) - 0.5; return std::sqrt(x * x + y * y) * M_SQRT2; } qreal DotsRoundSinusoidalScreentoneFunction::operator()(qreal x, qreal y) const { x = sinFunction(x); y = sinFunction(y); return (x * x + y * y) / 2.; } -constexpr qreal ellipseRatio = 1.2; +constexpr qreal ellipseRatioX = M_SQRT2 * 0.4; +constexpr qreal ellipseRatioY = M_SQRT2 * 0.6; qreal DotsEllipseLinearScreentoneFunction::operator()(qreal x, qreal y) const { - x = (std::abs(x - std::floor(x)) - 0.5) / ellipseRatio; - y = (std::abs(y - std::floor(y)) - 0.5) * ellipseRatio; + x = (std::abs(x - std::floor(x)) - 0.5) * ellipseRatioX; + y = (std::abs(y - std::floor(y)) - 0.5) * ellipseRatioY; return std::sqrt(x * x + y * y) * M_SQRT2; } qreal DotsEllipseSinusoidalScreentoneFunction::operator()(qreal x, qreal y) const { - x = sinFunction(x) / ellipseRatio; - y = sinFunction(y) * ellipseRatio; + x = sinFunction(x) * ellipseRatioX; + y = sinFunction(y) * ellipseRatioY; return (x * x + y * y) / 2.; } qreal DotsDiamondScreentoneFunction::operator()(qreal x, qreal y) const { x = triangleFunction(x); y = triangleFunction(y); return (y + x) / 2.; } qreal DotsSquareScreentoneFunction::operator()(qreal x, qreal y) const { x = triangleFunction(x); y = triangleFunction(y); return std::max(x, y); } qreal LinesStraightLinearScreentoneFunction::operator()(qreal x, qreal y) const { Q_UNUSED(x); return triangleFunction(y); } qreal LinesStraightSinusoidalScreentoneFunction::operator()(qreal x, qreal y) const { Q_UNUSED(x); y = sinFunction(y); return y * y; } qreal LinesSineWaveLinearScreentoneFunction::operator()(qreal x, qreal y) const { x = sinFunction(x); return triangleFunction(y + x * x); } qreal LinesSineWaveSinusoidalScreentoneFunction::operator()(qreal x, qreal y) const { x = sinFunction(x); y = sinFunction(y + x * x); return y * y; } qreal LinesTriangularWaveLinearScreentoneFunction::operator()(qreal x, qreal y) const { x = triangleFunction(x); return triangleFunction(y + x); } qreal LinesTriangularWaveSinusoidalScreentoneFunction::operator()(qreal x, qreal y) const { x = triangleFunction(x); y = sinFunction(y + x); return y * y; } qreal LinesSawToothWaveLinearScreentoneFunction::operator()(qreal x, qreal y) const { x = sawToothFunction(x); return triangleFunction(y + x); } qreal LinesSawToothWaveSinusoidalScreentoneFunction::operator()(qreal x, qreal y) const { x = sawToothFunction(x); y = sinFunction(y + x); return y * y; } qreal LinesCurtainsLinearScreentoneFunction::operator()(qreal x, qreal y) const { x = triangleFunction(x); return triangleFunction(y + x * x); } qreal LinesCurtainsSinusoidalScreentoneFunction::operator()(qreal x, qreal y) const { x = triangleFunction(x); y = sinFunction(y + x * x); return y * y; }