Commit 4cce8ca1 authored by Wolthera van Hövell's avatar Wolthera van Hövell 🛍
Browse files

Merge in krita-testing-wolthera (squashed)(GSoC 2015)

This implements the Tangent Normal Brush Engine, a normalize filter, a tilt-cursor
and modifications to the phongbumpmap filter.
Squashed commit of the following:

commit 3527bbf5acd3f49047a0c07547e9b5d515d100d8
Author: Wolthera van Hövell <griffinvalley@gmail.com>
Date:   Sun Aug 2 18:30:53 2015 +0200

    Add some Tangent Normal factory presets.

    Otherwise it won't revert to default right.

commit cbd37351e63c86c6201f60ac6410ad72c3fb9c2a
Merge: 7477061 8c8b58c
Author: Wolthera van Hövell <griffinvalley@gmail.com>
Date:   Sun Aug 2 17:32:40 2015 +0200

    Merge branch 'calligra/2.9' into krita-testing-wolthera

    Conflicts:
    	krita/plugins/paintops/libpaintop/kis_current_outline_fetcher.cpp

commit 74770618d639ac0da6e51f432e17f2c84da56e21
Author: Wolthera van Hövell <griffinvalley@gmail.com>
Date:   Sun Aug 2 17:20:04 2015 +0200

    Turn the Swizzle Preview into a Widget extending QLabel

    This allows for it to update instantly when the comboboxes update.

commit 38d0415bed146c879a3a4cc09219fc3023b644f3
Author: Wolthera van Hövell <griffinvalley@gmail.com>
Date:   Sun Aug 2 16:38:52 2015 +0200

    Make drawing angle to be influenced by the canvas angle.

    I did this because it was akward to use otherwise.
    This doesn't apply to the tilt/direction mix. So if people want the original behaviour
    they can use this one.

commit 24ad0a1b60089a338a4b36c3975bf27ffbbba7c0
Author: Wolthera van Hövell <griffinvalley@gmail.com>
Date:   Wed Jul 29 15:27:56 2015 +0200

    Fix normalise to work with floating point.

    It still doesn't output to 0-1 like you'd expect, but at the least it works a bit better.

commit b8dbceed68545bc8f51de35c9c77de329fd5050e
Author: Wolthera van Hövell <griffinvalley@gmail.com>
Date:   Tue Jul 28 23:00:55 2015 +0200

    Add Normalize Filter

    This filter takes the values of the channel and assigns them to a Qvector3d
    This is then normalizes, and those values are fed back into a color.
    This asures that the values are proper normal values.

    Doesn't work with float spaces yet, for some inexplicable reason

commit abf94976c34c2e7873c554b6123dd672d739e0d8
Author: Wolthera van Hövell <griffinvalley@gmail.com>
Date:   Tue Jul 28 18:03:43 2015 +0200

    cleanup

    Can't figure out how to deal with preview updating...

commit 017ba62f4d1bbb5b3d32501d63bbbaa73fa16243
Author: Wolthera van Hövell <griffinvalley@gmail.com>
Date:   Tue Jul 28 17:11:55 2015 +0200

    BUG 338011: Fix sharpness-mirror mode option

    Turns out that to render a mirrored mask, you need to actually render it.

commit ffb42bcf8f55efd67442fec9fa8e0d507e3f72ca
Author: Wolthera van Hövell <griffinvalley@gmail.com>
Date:   Tue Jul 28 16:48:50 2015 +0200

    Make sharpness work for tangent tilt option

commit 66e001802aaf2cc990349cac971e06a22bcbf96f
Author: Wolthera van Hövell <griffinvalley@gmail.com>
Date:   Tue Jul 28 16:22:35 2015 +0200

    Cleanup.

    Removed variables that weren't used, and noted variables that were used
    but not recognised by the compiler as Q_UNUSED

commit 3becd0e6be39e8d19c90bf8a4495bbf4bb2bb2c5
Author: Wolthera van Hövell <griffinvalley@gmail.com>
Date:   Tue Jul 28 16:02:53 2015 +0200

    Make it use the 8bit variety of the image colour space if the image colour space is RGBA

    So a CMYKA space will get sRGB, but a linear sRGB space will use the right profile.

commit 4b6ec179ef9b43195089bcf3ab413e4cf0933680
Author: Wolthera van Hövell <griffinvalley@gmail.com>
Date:   Tue Jul 28 15:21:42 2015 +0200

    Convert radian formula to use kis_global

    Remove todos in comments associated.

commit ce7bc9d848bb0f0f9b37ed81932543f0aa224bd0
Author: Wolthera van Hövell <griffinvalley@gmail.com>
Date:   Tue Jul 28 14:49:12 2015 +0200

    Change elevation to 1 slider and add tilt/direction mix

    Elevation is now not a range of two items, but rather a slider that
    is full range at 100% and only purple at 0%.

    Direction/Tilt mix will mix the drawing angle and tilt sensors.

commit 1876187dd7ddc6eaa1d6977d43bb951ac2edba1b
Author: Wolthera van Hövell <griffinvalley@gmail.com>
Date:   Tue Jul 28 12:41:23 2015 +0200

    Fix bug with direction taking 90 for the elevation

    This made it not work with the geometric tools.

    Ref T87

commit ec867a1449dc511bd69e917618a2ec4008b89c01
Author: Wolthera van Hövell <griffinvalley@gmail.com>
Date:   Sun Jul 26 11:01:59 2015 +0200

    Adding a preview to the tangent tilt options

commit d4807cca6b29496bfa24f1982271e03e7cf90e9c
Author: Wolthera van Hovell <griffinvalley@gmail.com>
Date:   Mon Jul 20 20:57:03 2015 +0200

    make tilt cursor also work for chalk.

    Fixes T88

commit d582e731c3736be676d9d5604eba9ef8fafa06da
Author: Wolthera van Hovell <griffinvalley@gmail.com>
Date:   Mon Jul 20 20:46:44 2015 +0200

    Add more options to the tangent normal map brush.

commit 5956a9e6c55f815f19e68556582e67908e6f1201
Author: Wolthera van Hovell <griffinvalley@gmail.com>
Date:   Mon Jul 20 15:17:19 2015 +0200

    Adding tilt-cursor to other brushengines, removing colour cursor entry

commit d6f9bbec74bc977441e3863a17d4e45e74a490e0
Author: Wolthera van Hovell <griffinvalley@gmail.com>
Date:   Sun Jul 19 21:13:06 2015 +0200

    Make rotation work with symettry multibrush

    Doesn't work with the snowflake and mirror options, but that's not as
    important as the symettry brush.

    fixes T130

commit 39727914ef052e164e88ec54794c3ff8049ea8b6
Merge: fb20900 e797d28
Author: Wolthera van Hovell <griffinvalley@gmail.com>
Date:   Sun Jul 19 16:12:04 2015 +0200

    Merge branch 'calligra/2.9' into krita-testing-wolthera

commit fb2090038f234b4769c58786d09a26241fef0895
Merge: 5dccb19 32ef906
Author: Wolthera van Hovell <griffinvalley@gmail.com>
Date:   Sun Jun 28 14:20:15 2015 +0200

    Merge branch 'calligra/2.9' into krita-testing-wolthera

    Conflicts:
    	krita/image/brushengine/kis_paint_information.cc
    	krita/image/brushengine/kis_paint_information.h

commit 5dccb19e7b01627a72af5687fa154ce150c41a72
Author: Wolthera van Hovell <griffinvalley@gmail.com>
Date:   Sun Jun 21 12:58:01 2015 +0200

    Fix the lights of the phongbumpmap filter for normalmaps

    I still don't like pentalis' way of handling the angle, but
    at the least this works fully now!

commit f0c4531618ff3c5517cc1e7fba31c2fdab1376be
Author: Wolthera van Hovell <griffinvalley@gmail.com>
Date:   Sun Jun 21 00:16:59 2015 +0200

    make some minor changes to the pixel processor

    still not right though

commit a67f8a146d5bddd2d217b4c35a074f32b29777ca
Author: Wolthera van Hovell <griffinvalley@gmail.com>
Date:   Sat Jun 20 21:13:15 2015 +0200

    Initial attempt to make the phong-bump-map filter accept normal maps

    This allow it to preview normal maps of course, and the result is a little smoother
    it still has issues with the lighting though

commit 0a660ad7f5900cf0adeab4f46f0870fdef816eb5
Author: Wolthera van Hovell <griffinvalley@gmail.com>
Date:   Sat Jun 20 15:07:25 2015 +0200

    removing unused functionality from the phong bumpmap filter

    otherwise I can't tell what's up or down anymore

commit 6e0a1fc3cd8a2aeba2e2aaad30140d9b45b23ca9
Author: Boudewijn Rempt <boud@valdyas.org>
Date:   Sat Jun 20 12:05:53 2015 +0200

    whitespace

commit b5c14decc028d18f3c3f1eec7c5d42e7f20affd1
Merge: bfbc94f 003f921
Author: Wolthera van Hovell <griffinvalley@gmail.com>
Date:   Sat Jun 20 10:39:13 2015 +0200

    Merge branch 'calligra/2.9' into krita-testing-wolthera

commit bfbc94f687d7cade4400b20fd12de20e8cac9df0
Author: Wolthera van Hovell <griffinvalley@gmail.com>
Date:   Tue Jun 16 18:54:25 2015 +0200

    Refactor the tangent tilt and canvas rotation involvement

    Now, the tangent tilt option understands how to mirror itself, and can be used
    in the mirror mode, as well, the multi-brush now can pass correctly rotated
    values to the tangent tilt, but it doesn't understand how to mirror for
    various reasons.

    Ref T130
    Ref T87

commit 31ee7e8a761fa9bfae6e85ef4cfaf236bc80fdd9
Author: Wolthera van Hovell <griffinvalley@gmail.com>
Date:   Tue Jun 16 01:14:08 2015 +0200

    Initial Implementation Tilt Cursor

    It's a little ugly, but it works for all brush-based paintops. I need to go
    back and modify tilt_option more to work with the mirror mode now. Also
    implemented strings for the color cursor, let's see where that is going to
    lead us...

    Ref T88
    Ref T87

commit 6de9aa089ac2ec9b708869df974cb41e2dbe7b8f
Author: Wolthera van Hovell <griffinvalley@gmail.com>
Date:   Wed Jun 10 15:22:20 2015 +0200

    delete log files

commit 3f74928a8313462ce0574dbefd02cc246ec7df7b
Author: Wolthera van Hovell <griffinvalley@gmail.com>
Date:   Wed Jun 10 15:17:23 2015 +0200

    Revive Tangent Normal Brush Engine with 2.9.5 optimisations included

    fixes T335

commit 6edac51708995d180a4bff387d57ff3fb263e0c0
Merge: 93cbe39 dfb4ad6
Author: Wolthera van Hovell <griffinvalley@gmail.com>
Date:   Wed Jun 10 13:57:51 2015 +0200

    Merge branch 'calligra/2.9' into krita-testing-wolthera

commit 93cbe392da36c3b11437f3b7ca895379656fda9c
Author: Wolthera van Hovell <griffinvalley@gmail.com>
Date:   Sat May 16 21:23:00 2015 +0200

    Implement elevation limiter.

    I tried implementing the direction limiter, but it doesn't work.
    Also figured out the defaults issue: It doesn't retreive from a kpp though.
    Maybe that is broken? Anyway, got nice defaults in place now.

    Ref T129
    Fixes T165

commit 523b67164ee27485ae81cff6323abd4992ce0372
Author: Wolthera van Hovell <griffinvalley@gmail.com>
Date:   Sat May 16 17:00:59 2015 +0200

    Let the tangent tilt be affect by the angle of the canvas

    Doesn't work for the multi-hand and figure drawing tools yet.

    ref T130

commit 527bbdd33f8b0ab1f3076000476ddad99eeee982
Merge: a9142e0 162244f
Author: Wolthera van Hovell <griffinvalley@gmail.com>
Date:   Sat May 16 14:15:41 2015 +0200

    Merge branch 'calligra/2.9' into krita-testing-wolthera

commit a9142e09f7129392bbff0b7113e8e0794fe42330
Author: Wolthera van Hovell <griffinvalley@gmail.com>
Date:   Sun Apr 26 19:50:53 2015 +0200

    Added tangent swizzle functionality.

    Several things are added in this commit:
    1. A UI for tangent normal map options.
    2. The option to switch tangent encoding.
    3. The ability to use tilt-direction, drawing angle or rotation for the
    direction parameter.
    4. A default brush for the tangent normal brush engine, but no clue how
    this is supossed to work...

commit 9cb2eb673184a07f2f4f5dbdc66878514e8bd7f9
Merge: c1f9702 a76adc6
Author: Wolthera van Hovell <griffinvalley@gmail.com>
Date:   Sun Apr 26 14:38:40 2015 +0200

    Merge branch 'calligra/2.9' into krita-testing-wolthera

commit c1f9702af512d7f253e930c18202ec6a0c3c1856
Merge: 5642267 697f455
Author: Wolthera van Hovell <griffinvalley@gmail.com>
Date:   Sun Apr 26 14:25:51 2015 +0200

    Merge branch 'calligra/2.9' into krita-testing-wolthera

commit 56422672c5cb245b58d0c300753a957230cbd4a9
Author: Wolthera van Hovell <griffinvalley@gmail.com>
Date:   Fri Apr 24 14:57:29 2015 +0200

    First commit tangent normal brush.

    It... paints, takes tilt as input, and paints the right colour...
    There's still a lot to be done though.
parent db51ec78
......@@ -106,6 +106,11 @@ Splat_wet_cells.kpp
Splatter_thin.kpp
Sponge_texture.kpp
Spray_splat.kpp
Tangent_normal_basic.kpp
Tangent_normal_drawing_angle.kpp
Tangent_normal_hairy.kpp
Tangent_normal_pixel.kpp
Tangent_normal_y_inverted.kpp
Texture_fuzzy.kpp
Texture_hair.kpp
Texture_leaves_fuzzy.kpp
......
......@@ -79,7 +79,8 @@ struct KisPaintInformation::Private {
speed = rhs.speed;
isHoveringMode = rhs.isHoveringMode;
currentDistanceInfo = rhs.currentDistanceInfo;
canvasRotation = rhs.canvasRotation;
canvasMirroredH = rhs.canvasMirroredH;
if (rhs.drawingAngleOverride) {
drawingAngleOverride.reset(new qreal(*rhs.drawingAngleOverride));
}
......@@ -96,6 +97,8 @@ struct KisPaintInformation::Private {
qreal time;
qreal speed;
bool isHoveringMode;
int canvasRotation;
bool canvasMirroredH;
QScopedPointer<qreal> drawingAngleOverride;
KisDistanceInformation *currentDistanceInfo;
......@@ -194,6 +197,7 @@ bool KisPaintInformation::isHoveringMode() const
return d->isHoveringMode;
}
KisPaintInformation
KisPaintInformation::createHoveringModeInfo(const QPointF &pos,
qreal pressure,
......@@ -201,7 +205,9 @@ KisPaintInformation::createHoveringModeInfo(const QPointF &pos,
qreal rotation,
qreal tangentialPressure,
qreal perspective,
qreal speed)
qreal speed,
int canvasrotation,
bool canvasMirroredH)
{
KisPaintInformation info(pos,
pressure,
......@@ -210,9 +216,38 @@ KisPaintInformation::createHoveringModeInfo(const QPointF &pos,
tangentialPressure,
perspective, 0, speed);
info.d->isHoveringMode = true;
info.d->canvasRotation = canvasrotation;
info.d->canvasMirroredH = canvasMirroredH;
return info;
}
int KisPaintInformation::canvasRotation() const
{
return d->canvasRotation;
}
void KisPaintInformation::setCanvasRotation(int rot)
{
if (rot<0) {
d->canvasRotation= 360- abs(rot % 360);
} else {
d->canvasRotation= rot % 360;
}
}
bool KisPaintInformation::canvasMirroredH() const
{
return d->canvasMirroredH;
}
void KisPaintInformation::setCanvasHorizontalMirrorState(bool mir)
{
d->canvasMirroredH = mir;
}
void KisPaintInformation::toXML(QDomDocument&, QDomElement& e) const
{
// hovering mode infos are not supposed to be saved
......@@ -427,6 +462,8 @@ KisPaintInformation KisPaintInformation::mix(const QPointF& p, qreal t, const Ki
KisPaintInformation result(p, pressure, xTilt, yTilt, rotation, tangentialPressure, perspective, time, speed);
KIS_ASSERT_RECOVER_NOOP(pi1.isHoveringMode() == pi2.isHoveringMode());
result.d->isHoveringMode = pi1.isHoveringMode();
result.d->canvasRotation = pi2.canvasRotation();
result.d->canvasMirroredH = pi2.canvasMirroredH();
return result;
}
......
......@@ -208,8 +208,28 @@ public:
qreal rotation = 0.0,
qreal tangentialPressure = 0.0,
qreal perspective = 1.0,
qreal speed = 0.0);
qreal speed = 0.0,
int canvasrotation = 0,
bool canvasMirroredH = false);
/**
*Returns the canvas rotation if that has been given to the kispaintinformation.
*/
int canvasRotation() const;
/**
*set the canvas rotation.
*/
void setCanvasRotation(int rotation);
/*
*Whether the canvas is mirrored for the paint-operation.
*/
bool canvasMirroredH() const;
/*
*Set whether the canvas is mirrored for the paint-operation.
*/
void setCanvasHorizontalMirrorState(bool mir);
void toXML(QDomDocument&, QDomElement&) const;
static KisPaintInformation fromXML(const QDomElement&);
......
......@@ -228,8 +228,23 @@ QString KisPaintOpSettings::indirectPaintingCompositeOp() const
QPainterPath KisPaintOpSettings::brushOutline(const KisPaintInformation &info, OutlineMode mode) const
{
QPainterPath path;
if (mode == CursorIsOutline || mode == CursorIsCircleOutline) {
path = ellipseOutline(10, 10, 1.0, 0).translated(info.pos());
if (mode == CursorIsOutline || mode == CursorIsCircleOutline || mode == CursorTiltOutline) {
path = ellipseOutline(10, 10, 1.0, 0);
if (mode == CursorTiltOutline) {
QPainterPath tiltLine;
QLineF tiltAngle(QPointF(0.0,0.0), QPointF(0.0,3.0));
tiltAngle.setLength(50.0 * (1 - info.tiltElevation(info, 60.0, 60.0, true)));
tiltAngle.setAngle((360.0 - fmod(KisPaintInformation::tiltDirection(info, true) * 360.0 + 270.0, 360.0))-2.0);
tiltLine.moveTo(tiltAngle.p1());
tiltLine.lineTo(tiltAngle.p2());
tiltAngle.setAngle((360.0 - fmod(KisPaintInformation::tiltDirection(info, true) * 360.0 + 270.0, 360.0))+2.0);
tiltLine.lineTo(tiltAngle.p2());
tiltLine.lineTo(tiltAngle.p1());
path.addPath(tiltLine);
}
path.translate(info.pos());
}
return path;
......
......@@ -129,7 +129,9 @@ public:
enum OutlineMode {
CursorIsOutline = 1, ///< When this mode is set, an outline is painted around the cursor
CursorIsCircleOutline,
CursorNoOutline
CursorNoOutline,
CursorTiltOutline,
CursorColorOutline
};
/**
......
......@@ -45,6 +45,8 @@ enum OutlineStyle {
OUTLINE_NONE = 0,
OUTLINE_CIRCLE,
OUTLINE_FULL,
OUTLINE_TILT,
OUTLINE_COLOR,
N_OUTLINE_STYLE_SIZE
};
......
......@@ -22,3 +22,4 @@ add_subdirectory( dodgeburn )
add_subdirectory( phongbumpmap )
add_subdirectory( posterize )
add_subdirectory( indexcolors )
add_subdirectory( normalize )
set(kritanormalize_PART_SRCS kis_normalize.cpp )
kde4_add_plugin(kritanormalize ${kritanormalize_PART_SRCS})
target_link_libraries(kritanormalize kritaui)
install(TARGETS kritanormalize DESTINATION ${PLUGIN_INSTALL_DIR})
########### install files ###############
install( FILES kritanormalize.desktop DESTINATION ${SERVICES_INSTALL_DIR}/calligra)
/*
*
* Copyright (c) 2015 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com>
* 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_normalize.h"
#include <stdlib.h>
#include <vector>
#include <QPoint>
#include <QTime>
#include <QVector3D>
#include <klocale.h>
#include <kis_debug.h>
#include <kpluginfactory.h>
#include <kis_processing_information.h>
#include <kis_types.h>
#include <kis_selection.h>
#include <kis_layer.h>
#include <filter/kis_filter_registry.h>
#include <kis_global.h>
#include <KoColorSpaceMaths.h>
#include <filter/kis_color_transformation_configuration.h>
K_PLUGIN_FACTORY(KritaNormalizeFactory, registerPlugin<Normalize>();)
K_EXPORT_PLUGIN(KritaNormalizeFactory("krita"))
Normalize::Normalize(QObject *parent, const QVariantList &)
: QObject(parent)
{
KisFilterRegistry::instance()->add(KisFilterSP(new KisFilterNormalize()));
}
Normalize::~Normalize()
{
}
KisFilterNormalize::KisFilterNormalize()
: KisColorTransformationFilter(KoID("normalize" , i18n("Normalize")),
KisFilter::categoryMap(), i18n("&Normalize..."))
{
setColorSpaceIndependence(FULLY_INDEPENDENT);
setSupportsPainting(true);
setShowConfigurationWidget(false);
}
KoColorTransformation* KisFilterNormalize::createTransformation(const KoColorSpace* cs, const KisFilterConfiguration* config) const
{
Q_UNUSED(config);
return new KisNormalizeTransformation(cs);
}
KisNormalizeTransformation::KisNormalizeTransformation(const KoColorSpace* cs) : m_colorSpace(cs), m_psize(cs->pixelSize())
{
}
void KisNormalizeTransformation::transform(const quint8* src, quint8* dst, qint32 nPixels) const
{
QVector3D normal_vector;
QVector<float> channelValues(4);
quint16 m_rgba[4];
//if (m_colorSpace->colorDepthId().id()!="F16" && m_colorSpace->colorDepthId().id()!="F32" && m_colorSpace->colorDepthId().id()!="F64") {
/* I don't know why, but the results of this are unexpected with a floating point space.
* And manipulating the pixels gives strange results.
*/
while (nPixels--) {
m_colorSpace->normalisedChannelsValue(src, channelValues);
normal_vector.setX(channelValues[2]*2-1.0);
normal_vector.setY(channelValues[1]*2-1.0);
normal_vector.setZ(channelValues[0]*2-1.0);
normal_vector.normalize();
channelValues[0]=normal_vector.z()*0.5+0.5;
channelValues[1]=normal_vector.y()*0.5+0.5;
channelValues[2]=normal_vector.x()*0.5+0.5;
//channelValues[3]=1.0;
m_colorSpace->fromNormalisedChannelsValue(dst, channelValues);
dst[3]=src[3];
src += m_psize;
dst += m_psize;
}
/* } else {
while (nPixels--) {
m_colorSpace->normalisedChannelsValue(src, channelValues);
qreal max = qMax(channelValues[2], qMax(channelValues[1], channelValues[0]));
qreal min = qMin(channelValues[2], qMin(channelValues[1], channelValues[0]));
qreal range = max-min;
normal_vector.setX( ((channelValues[2]-min)/range) *2.0-1.0);
normal_vector.setY( ((channelValues[1]-min)/range) *2.0-1.0);
normal_vector.setZ( ((channelValues[0]-min)/range) *2.0-1.0);
normal_vector.normalize();
channelValues[2]=normal_vector.x()*0.5+0.5;
channelValues[1]=normal_vector.y()*0.5+0.5;
channelValues[0]=normal_vector.z()*0.5+0.5;
//channelValues[3]=1.0;
m_colorSpace->fromNormalisedChannelsValue(dst, channelValues);
dst[3]=src[3];
//hack to trunucate values.
m_colorSpace->toRgbA16(dst, reinterpret_cast<quint8 *>(m_rgba), 1);
m_colorSpace->fromRgbA16(reinterpret_cast<quint8 *>(m_rgba), dst, 1);
src += m_psize;
dst += m_psize;
}
}*/
}
\ No newline at end of file
/*
* Copyright (c) 2015 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com>
*
* 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 NORMALIZE_H
#define NORMALIZE_H
#include <QObject>
#include <QVariant>
#include "filter/kis_color_transformation_filter.h"
class Normalize : public QObject
{
Q_OBJECT
public:
Normalize(QObject *parent, const QVariantList &);
virtual ~Normalize();
};
class KisFilterNormalize : public KisColorTransformationFilter
{
public:
KisFilterNormalize();
public:
virtual KoColorTransformation* createTransformation(const KoColorSpace* cs, const KisFilterConfiguration* config) const;
};
class KisNormalizeTransformation : public KoColorTransformation
{
public:
KisNormalizeTransformation(const KoColorSpace* cs);
virtual void transform(const quint8* src, quint8* dst, qint32 nPixels) const;
private:
const KoColorSpace* m_colorSpace;
quint32 m_psize;
};
#endif
\ No newline at end of file
[Desktop Entry]
Name=Normalize Filter
Name[bs]=
Name[ca]=
Name[da]=
Name[de]=
Name[en_GB]=
Name[es]=
Name[fi]=
Name[fr]=
Name[it]=
Name[ja]=
Name[nb]=
Name[nl]=
Name[pl]=
Name[pt]=
Name[pt_BR]=
Name[sk]=
Name[sv]=
Name[uk]=
Name[x-test]=xxNormalize Filterxx
Comment=Normalize the color channels.
Comment[bs]=
Comment[ca]=
Comment[da]=
Comment[de]=
Comment[en_GB]=
Comment[es]=
Comment[fr]=
Comment[it]=
Comment[ja]=
Comment[nb]=
Comment[nl]=
Comment[pl]=
Comment[pt]=
Comment[pt_BR]=
Comment[sk]=
Comment[sv]=
Comment[uk]=
Comment[x-test]=xxNormalize the color channelsxx
X-KDE-ServiceTypes=Krita/Filter
Type=Service
X-KDE-Library=kritanormalize
X-Krita-Version=29
......@@ -61,7 +61,8 @@ KisPhongBumpmapConfigWidget::KisPhongBumpmapConfigWidget(const KisPaintDeviceSP
connect(m_page->inclinationSpinBox2, SIGNAL(valueChanged(int)), SIGNAL(sigConfigurationItemChanged()));
connect(m_page->inclinationSpinBox3, SIGNAL(valueChanged(int)), SIGNAL(sigConfigurationItemChanged()));
connect(m_page->inclinationSpinBox4, SIGNAL(valueChanged(int)), SIGNAL(sigConfigurationItemChanged()));
connect(m_page->useNormalMap, SIGNAL(toggled(bool)), SIGNAL(sigConfigurationItemChanged()));
connect(m_page->diffuseReflectivityGroup, SIGNAL(toggled(bool)), SIGNAL(sigConfigurationItemChanged()));
connect(m_page->specularReflectivityGroup, SIGNAL(toggled(bool)), SIGNAL(sigConfigurationItemChanged()));
......@@ -100,6 +101,7 @@ void KisPhongBumpmapConfigWidget::setConfiguration(const KisPropertiesConfigurat
m_page->diffuseReflectivityKisDoubleSliderSpinBox->setValue( config->getDouble(PHONG_DIFFUSE_REFLECTIVITY) );
m_page->specularReflectivityKisDoubleSliderSpinBox->setValue( config->getDouble(PHONG_SPECULAR_REFLECTIVITY) );
m_page->shinynessExponentKisSliderSpinBox->setValue( config->getInt(PHONG_SHINYNESS_EXPONENT) );
m_page->useNormalMap->setChecked( config->getBool(USE_NORMALMAP_IS_ENABLED) );
m_page->diffuseReflectivityGroup->setChecked( config->getBool(PHONG_DIFFUSE_REFLECTIVITY_IS_ENABLED) );
m_page->specularReflectivityGroup->setChecked( config->getBool(PHONG_SPECULAR_REFLECTIVITY_IS_ENABLED) );
// NOTE: Indexes are off by 1 simply because arrays start at 0 and the GUI naming scheme started at 1
......@@ -129,6 +131,8 @@ KisPropertiesConfiguration *KisPhongBumpmapConfigWidget::configuration() const
{
KisFilterConfiguration *config = new KisFilterConfiguration("phongbumpmap", 2);
config->setProperty(PHONG_HEIGHT_CHANNEL, m_page->heightChannelComboBox->currentText());
config->setProperty(USE_NORMALMAP_IS_ENABLED, m_page->useNormalMap->isChecked());
config->setProperty(PHONG_AMBIENT_REFLECTIVITY, m_page->ambientReflectivityKisDoubleSliderSpinBox->value());
config->setProperty(PHONG_DIFFUSE_REFLECTIVITY, m_page->diffuseReflectivityKisDoubleSliderSpinBox->value());
config->setProperty(PHONG_SPECULAR_REFLECTIVITY, m_page->specularReflectivityKisDoubleSliderSpinBox->value());
......
......@@ -49,18 +49,14 @@ void KisFilterPhongBumpmap::processImpl(KisPaintDeviceSP device,
if (!config) return;
if (progressUpdater) progressUpdater->setProgress(0);
// Benchmark
QTime timer, timerE;
QString userChosenHeightChannel = config->getString(PHONG_HEIGHT_CHANNEL, "FAIL");
bool m_usenormalmap = config->getBool(USE_NORMALMAP_IS_ENABLED);
if (userChosenHeightChannel == "FAIL") {
qDebug("FIX YOUR FILTER");
return;
}
timer.start();
KoChannelInfo *m_heightChannel = 0;
......@@ -69,6 +65,7 @@ void KisFilterPhongBumpmap::processImpl(KisPaintDeviceSP device,
m_heightChannel = channel;
}
}
if (!m_heightChannel) {
m_heightChannel = device->colorSpace()->channels().first();
}
......@@ -76,8 +73,9 @@ void KisFilterPhongBumpmap::processImpl(KisPaintDeviceSP device,
QRect inputArea = applyRect;
QRect outputArea = applyRect;
inputArea.adjust(-1, -1, 1, 1);
if (m_usenormalmap==false) {
inputArea.adjust(-1, -1, 1, 1);
}
quint32 posup;
quint32 posdown;
......@@ -98,9 +96,9 @@ void KisFilterPhongBumpmap::processImpl(KisPaintDeviceSP device,
const quint32 bytesToFillBumpmapArea = pixelsOfOutputArea * pixelSize;
QVector<quint8> bumpmap(bytesToFillBumpmapArea);
quint8 *bumpmapDataPointer = bumpmap.data();
quint32 ki = KoChannelInfo::displayPositionToChannelIndex(m_heightChannel->displayPosition(),
device->colorSpace()->channels());
quint32 ki = KoChannelInfo::displayPositionToChannelIndex(m_heightChannel->displayPosition(), device->colorSpace()->channels());
PhongPixelProcessor tileRenderer(pixelsOfInputArea, config);
if (progressUpdater) progressUpdater->setProgress(2);
......@@ -119,33 +117,59 @@ void KisFilterPhongBumpmap::processImpl(KisPaintDeviceSP device,
inputArea.width()
);
for (qint32 srcRow = 0; srcRow < inputArea.height(); ++srcRow) {
do {
const quint8 *data = iterator->oldRawData();
tileRenderer.realheightmap[curPixel] = toDoubleFuncPtr[ki](data, device->colorSpace()->channels()[ki]->pos());
curPixel++;
if (m_usenormalmap==false) {
for (qint32 srcRow = 0; srcRow < inputArea.height(); ++srcRow) {
do {
const quint8 *data = iterator->oldRawData();
tileRenderer.realheightmap[curPixel] = toDoubleFuncPtr[ki](data, device->colorSpace()->channels()[ki]->pos());
curPixel++;
}
while (iterator->nextPixel());
iterator->nextRow();
}
while (iterator->nextPixel());
iterator->nextRow();
}
if (progressUpdater) progressUpdater->setProgress(50);
const int tileHeightMinus1 = inputArea.height() - 1;
const int tileWidthMinus1 = inputArea.width() - 1;
if (progressUpdater) progressUpdater->setProgress(50);
// Foreach INNER pixel in tile
for (int y = 1; y < tileHeightMinus1; ++y) {
for (int x = 1; x < tileWidthMinus1; ++x) {
posup = (y + 1) * inputArea.width() + x;
posdown = (y - 1) * inputArea.width() + x;
posleft = y * inputArea.width() + x - 1;
posright = y * inputArea.width() + x + 1;
memcpy(bumpmapDataPointer,
tileRenderer.testingHeightmapIlluminatePixel(posup, posdown, posleft, posright).data(),
pixelSize);
bumpmapDataPointer += pixelSize;
const int tileHeightMinus1 = inputArea.height() - 1;
const int tileWidthMinus1 = inputArea.width() - 1;
// Foreach INNER pixel in tile
for (int y = 1; y < tileHeightMinus1; ++y) {
for (int x = 1; x < tileWidthMinus1; ++x) {
posup = (y + 1) * inputArea.width() + x;
posdown = (y - 1) * inputArea.width() + x;
posleft = y * inputArea.width() + x - 1;
posright = y * inputArea.width() + x + 1;
memcpy(bumpmapDataPointer,
tileRenderer.IlluminatePixelFromHeightmap(posup, posdown, posleft, posright).data(),
pixelSize);
bumpmapDataPointer += pixelSize;
}
}