Commit fc450e84 authored by Dmitry Kazakov's avatar Dmitry Kazakov

Merge remote-tracking branch 'origin/krita-testing-kazakov'

parents fdc97650 f342180f
......@@ -2,11 +2,22 @@ install( FILES
bilinear_gradient.frag
conical_gradient.frag
conical_symetric_gradient.frag
highq_downscale.frag
matrix_transform.vert
matrix_transform_legacy.vert
simple_texture.frag
simple_texture_legacy.frag
highq_downscale_preface.frag.inc
highq_downscale_main.frag.inc
highq_downscale_main_ocio.frag.inc
simple_texture_preface.frag.inc
simple_texture_main.frag.inc
simple_texture_main_ocio.frag.inc
simple_texture_legacy_preface.frag.inc
simple_texture_legacy_main.frag.inc
simple_texture_legacy_main_ocio.frag.inc
cursor.vert
cursor.frag
linear_gradient.frag
......
void main() {
if (viewportScale < 0.5 - eps) {
fragColor = filterPureLinear8(texture0, v_textureCoordinate.st);
} else {
fragColor = texture2D(texture0, v_textureCoordinate.st);
}
}
uniform sampler3D texture1;
void main() {
vec4 col;
if (viewportScale < 0.5 - eps) {
col = filterPureLinear8(texture0, v_textureCoordinate.st);
} else {
col = texture2D(texture0, v_textureCoordinate.st);
}
fragColor = OCIODisplay(col, texture1);
}
......@@ -61,12 +61,3 @@ vec4 filterPureLinear8(sampler2D texture, vec2 texcoord)
return (p1 + p2 + p3 + p4 + p5 + p6) / vec4(11.0);
}
void main() {
if (viewportScale < 0.5 - eps) {
fragColor = filterPureLinear8(texture0, v_textureCoordinate.st);
} else {
fragColor = texture2D(texture0, v_textureCoordinate.st);
}
}
void main() {
gl_FragColor = texture2D(texture0, v_textureCoordinate.st);
}
uniform sampler3D texture1;
void main() {
vec4 col = texture2D(texture0, v_textureCoordinate.st);
gl_FragColor = OCIODisplay(col, texture1);
}
......@@ -5,6 +5,3 @@ uniform sampler2D texture0;
varying mediump vec4 v_textureCoordinate;
void main() {
gl_FragColor = texture2D(texture0, v_textureCoordinate.st);
}
void main() {
fragColor = texture2D(texture0, v_textureCoordinate.st);
}
uniform sampler3D texture1;
void main() {
vec4 col = texture2D(texture0, v_textureCoordinate.st);
fragColor = OCIODisplay(col, texture1);
}
......@@ -7,6 +7,3 @@ uniform sampler2D texture0;
in vec4 v_textureCoordinate;
out vec4 fragColor;
void main() {
fragColor = texture2D(texture0, v_textureCoordinate.st);
}
/*
* Copyright (c) 2014 Dmitry Kazakov <dimula73@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 __KIS_SIGNALS_BLOCKER_H
#define __KIS_SIGNALS_BLOCKER_H
/**
* Block QObject's signals in a safe and sane way.
*
* Avoid using direct calls to QObject::blockSignals(bool),
* because:
*
* 1) They are not safe. One beautifully sunny day someone (it might
* easily be you youself) will forget about these call and will put
* a 'return' statement somewhere among the lines. Surely this is
* not what you expect to happen.
*
* 2) Two lines of blocking for every line of access can easily make
* the code unreadable.
*/
class KisSignalsBlocker
{
public:
KisSignalsBlocker(QObject *object)
: m_object(object)
{
m_object->blockSignals(true);
}
~KisSignalsBlocker()
{
m_object->blockSignals(false);
}
private:
Q_DISABLE_COPY(KisSignalsBlocker);
private:
QObject *m_object;
};
#endif /* __KIS_SIGNALS_BLOCKER_H */
......@@ -220,6 +220,10 @@ typedef KisStrokeWSP KisStrokeId;
class KisFilterConfiguration;
typedef QSharedPointer<KisFilterConfiguration> KisSafeFilterConfigurationSP;
class KisDisplayFilter;
typedef QSharedPointer<KisDisplayFilter> KisDisplayFilterSP;
#include <QSharedPointer>
#include <QWeakPointer>
#include <kis_shared_ptr.h>
......
......@@ -24,6 +24,7 @@ kis_color_selector_triangle.cpp
kis_color_selector_simple.cpp
kis_color_selector_wheel.cpp
kis_color_selector_combo_box.cpp
kis_color_selector_base_proxy.cpp
)
kde4_add_ui_files(KRITA_COLORSELECTORNG_PART_SRCS
......
/*
* Copyright (c) 2014 Dmitry Kazakov <dimula73@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 __KIS_ACS_PIXEL_CACHE_RENDERER_H
#define __KIS_ACS_PIXEL_CACHE_RENDERER_H
#include "KoColorSpace.h"
#include "kis_paint_device.h"
#include "kis_iterator_ng.h"
#include "kis_display_color_converter.h"
namespace Acs {
class PixelCacheRenderer {
public:
/**
* \p Picker class must provide one method:
* - KoColor Picker::colorAt(int x, int y);
*/
template <class Picker>
static void render(Picker *picker,
const KisDisplayColorConverter *converter,
const QRect &pickRect,
KisPaintDeviceSP &realPixelCache,
QImage &pixelCache,
QPoint &pixelCacheOffset)
{
const KoColorSpace *cacheColorSpace = converter->paintingColorSpace();
const int pixelSize = cacheColorSpace->pixelSize();
realPixelCache = new KisPaintDevice(cacheColorSpace);
KoColor color;
KisSequentialIterator it(realPixelCache, pickRect);
do {
color = picker->colorAt(it.x(), it.y());
memcpy(it.rawData(), color.data(), pixelSize);
} while (it.nextPixel());
// NOTE: toQImage() function of the converter copies exactBounds() only!
pixelCache = converter->toQImage(realPixelCache);
pixelCacheOffset = realPixelCache->exactBounds().topLeft() - pickRect.topLeft();
}
};
}
#endif /* __KIS_ACS_PIXEL_CACHE_RENDERER_H */
/*
* Copyright (c) 2014 Dmitry Kazakov <dimula73@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 __KIS_ACS_TYPES_H
#define __KIS_ACS_TYPES_H
#include <QPoint>
#include <KoColor.h>
namespace Acs {
enum ColorRole {Foreground, Background};
inline ColorRole buttonToRole(Qt::MouseButton button) {
return button == Qt::LeftButton ? Acs::Foreground : Acs::Background;
}
inline ColorRole buttonsToRole(Qt::MouseButton button, Qt::MouseButtons buttons) {
return button == Qt::LeftButton || buttons & Qt::LeftButton ? Acs::Foreground : Acs::Background;
}
template <class ResourceProvider>
void setCurrentColor(ResourceProvider *provider, ColorRole role, const KoColor &color) {
if (role == Acs::Foreground) {
provider->setFGColor(color);
} else {
provider->setBGColor(color);
}
}
template <class ResourceProvider>
KoColor currentColor(ResourceProvider *provider, ColorRole role) {
return role == Acs::Foreground ? provider->fgColor() : provider->bgColor();
}
template <class PaintDeviceSP>
KoColor pickColor(PaintDeviceSP device, const QPoint &pt) {
KoColor color;
(void) device->pixel(pt.x(), pt.y(), &color);
return color;
}
template <class PaintDeviceSP>
void setColor(PaintDeviceSP device, const QPoint &pt, const KoColor &color) {
(void) device->setPixel(pt.x(), pt.y(), color);
}
}
#endif /* __KIS_ACS_TYPES_H */
......@@ -49,7 +49,7 @@ void KisColorHistory::setCanvas(KisCanvas2 *canvas)
m_resourceProvider = canvas->view()->resourceProvider();
connect(canvas->view()->resourceProvider(), SIGNAL(sigFGColorUsed(KoColor)),
this, SLOT(commitColor(KoColor)), Qt::UniqueConnection);
this, SLOT(addColorToHistory(KoColor)), Qt::UniqueConnection);
}
KisColorSelectorBase* KisColorHistory::createPopup() const
......@@ -61,7 +61,7 @@ KisColorSelectorBase* KisColorHistory::createPopup() const
return ret;
}
void KisColorHistory::commitColor(const KoColor& color)
void KisColorHistory::addColorToHistory(const KoColor& color)
{
// don't add color in erase mode. See https://bugs.kde.org/show_bug.cgi?id=298940
if (m_resourceProvider && m_resourceProvider->currentCompositeOp() == COMPOSITE_ERASE) return;
......
......@@ -35,7 +35,7 @@ protected:
KisColorSelectorBase* createPopup() const;
public slots:
void commitColor(const KoColor& color);
void addColorToHistory(const KoColor& color);
private:
QList<KoColor> m_colorHistory;
......
......@@ -29,6 +29,8 @@
#include "kis_canvas2.h"
#include "KoCanvasResourceManager.h"
#include "kis_display_color_converter.h"
KisColorPatches::KisColorPatches(QString configPrefix, QWidget *parent) :
KisColorSelectorBase(parent), m_allowColorListChangeGuard(true), m_scrollValue(0), m_configPrefix(configPrefix)
......@@ -85,11 +87,13 @@ void KisColorPatches::paintEvent(QPaintEvent* e)
col = i/numPatchesInACol;
}
QColor qcolor = converter()->toQColor(m_colors.at(i-m_buttonList.size()));
painter.fillRect(col*m_patchWidth,
row*m_patchHeight,
m_patchWidth,
m_patchHeight,
m_colors.at(i-m_buttonList.size()).toQColor());
qcolor);
}
QWidget::paintEvent(e);
......@@ -168,7 +172,7 @@ void KisColorPatches::mousePressEvent(QMouseEvent *event)
if(event->isAccepted())
return;
updateColorPreview(koColor.toQColor());
updateColorPreview(koColor);
if (event->button() == Qt::LeftButton)
m_dragStartPos = event->pos();
......@@ -194,7 +198,7 @@ void KisColorPatches::mouseMoveEvent(QMouseEvent *event)
QDrag *drag = new QDrag(this);
QMimeData *mimeData = new QMimeData;
QColor color = koColor.toQColor();
QColor color = converter()->toQColor(koColor);
mimeData->setColorData(color);
mimeData->setText(color.name());
drag->setMimeData(mimeData);
......
......@@ -33,15 +33,13 @@ public:
explicit KisColorPatches(QString configPrefix, QWidget *parent = 0);
enum Direction { Horizontal, Vertical };
void setColors(QList<KoColor> colors);
QList<KoColor> colors() const {return m_colors;}
virtual void setCanvas(KisCanvas2 *canvas) { m_canvas = canvas; }
virtual void unsetCanvas() { KisColorSelectorBase::unsetCanvas(); m_canvas = 0;}
public slots:
void updateSettings();
protected:
void setColors(QList<KoColor> colors);
QList<KoColor> colors() const {return m_colors;}
void paintEvent(QPaintEvent *);
void wheelEvent(QWheelEvent *);
void resizeEvent(QResizeEvent *);
......
......@@ -41,6 +41,8 @@
#include "kis_color_selector_wheel.h"
#include "kis_color_selector_container.h"
#include "kis_canvas2.h"
#include "kis_signal_compressor.h"
KisColorSelector::KisColorSelector(Configuration conf, QWidget* parent)
: KisColorSelectorBase(parent),
......@@ -55,6 +57,7 @@ KisColorSelector::KisColorSelector(Configuration conf, QWidget* parent)
m_blipDisplay(true)
{
init();
updateSettings();
setConfiguration(conf);
}
......@@ -78,7 +81,7 @@ KisColorSelector::KisColorSelector(QWidget* parent)
KisColorSelectorBase* KisColorSelector::createPopup() const
{
KisColorSelectorBase* popup = new KisColorSelector(0);
popup->setColor(m_lastColor);
popup->setColor(m_lastRealColor);
return popup;
}
......@@ -125,8 +128,8 @@ void KisColorSelector::setConfiguration(Configuration conf)
connect(m_subComponent, SIGNAL(paramChanged(qreal,qreal,qreal,qreal,qreal)),
m_mainComponent, SLOT(setParam(qreal,qreal,qreal,qreal, qreal)), Qt::UniqueConnection);
connect(m_mainComponent, SIGNAL(update()), m_updateTimer, SLOT(start()), Qt::UniqueConnection);
connect(m_subComponent, SIGNAL(update()), m_updateTimer, SLOT(start()), Qt::UniqueConnection);
connect(m_mainComponent, SIGNAL(update()), m_signalCompressor, SLOT(start()), Qt::UniqueConnection);
connect(m_subComponent, SIGNAL(update()), m_signalCompressor, SLOT(start()), Qt::UniqueConnection);
m_mainComponent->setConfiguration(m_configuration.mainTypeParameter, m_configuration.mainType);
m_subComponent->setConfiguration(m_configuration.subTypeParameter, m_configuration.subType);
......@@ -147,6 +150,19 @@ void KisColorSelector::updateSettings()
setConfiguration(Configuration::fromString(cfg.readEntry("colorSelectorConfiguration", KisColorSelector::Configuration().toString())));
}
void KisColorSelector::reset()
{
KisColorSelectorBase::reset();
if (m_mainComponent) {
m_mainComponent->setDirty();
}
if (m_subComponent) {
m_subComponent->setDirty();
}
}
void KisColorSelector::paintEvent(QPaintEvent* e)
{
Q_UNUSED(e);
......@@ -221,13 +237,10 @@ void KisColorSelector::resizeEvent(QResizeEvent* e) {
}
}
}
if(m_canvas && m_canvas->resourceManager()) {
if (m_lastColorRole==Foreground) {
setColor(m_canvas->resourceManager()->foregroundColor().toQColor());
} else if (m_lastColorRole==Background) {
setColor(m_canvas->resourceManager()->backgroundColor().toQColor());
}
}
// reset the currect color after resizing the widget
setColor(m_lastRealColor);
KisColorSelectorBase::resizeEvent(e);
}
......@@ -261,18 +274,12 @@ void KisColorSelector::mouseReleaseEvent(QMouseEvent* e)
KisColorSelectorBase::mousePressEvent(e);
if(!e->isAccepted() &&
m_lastColor != m_currentColor &&
m_currentColor.isValid()) {
m_lastColor=m_currentColor;
if(e->button() == Qt::LeftButton)
{
m_lastColorRole=Foreground;}
else if (e->button() == Qt::RightButton)
{
m_lastColorRole=Background;}
commitColor(KoColor(m_currentColor, colorSpace()), m_lastColorRole);
!(m_lastRealColor == m_currentRealColor)) {
m_lastRealColor = m_currentRealColor;
m_lastColorRole = Acs::buttonToRole(e->button());
updateColor(m_lastRealColor, m_lastColorRole, false);
e->accept();
}
......@@ -281,18 +288,16 @@ void KisColorSelector::mouseReleaseEvent(QMouseEvent* e)
bool KisColorSelector::displaySettingsButton()
{
if(dynamic_cast<KisColorSelectorContainer*>(parent())!=0)
return true;
else
return false;
return dynamic_cast<KisColorSelectorContainer*>(parent());
}
void KisColorSelector::setColor(const QColor &color)
void KisColorSelector::setColor(const KoColor &color)
{
m_mainComponent->setColor(color);
m_subComponent->setColor(color);
m_lastColor=color;
update();
m_lastRealColor = color;
m_signalCompressor->start();
}
void KisColorSelector::mouseEvent(QMouseEvent *e)
......@@ -300,18 +305,13 @@ void KisColorSelector::mouseEvent(QMouseEvent *e)
if (m_grabbingComponent && (e->buttons() & Qt::LeftButton || e->buttons() & Qt::RightButton)) {
m_grabbingComponent->mouseEvent(e->x(), e->y());
m_currentColor=m_mainComponent->currentColor();
KoColor kocolor(m_currentColor, colorSpace());
updateColorPreview(kocolor.toQColor());
if (e->buttons() & Qt::LeftButton) {
commitColor(kocolor, Foreground);
}
else if (e->buttons() & Qt::RightButton) {
commitColor(kocolor, Background);
}
KoColor color = m_mainComponent->currentColor();
m_currentRealColor = color;
updateColorPreview(color);
Acs::ColorRole role = Acs::buttonsToRole(e->button(), e->buttons());
updateColor(color, role, false);
}
}
......@@ -319,7 +319,7 @@ void KisColorSelector::init()
{
setAcceptDrops(true);
m_lastColorRole = Foreground;
m_lastColorRole = Acs::Foreground;
m_ring = new KisColorSelectorRing(this);
m_triangle = new KisColorSelectorTriangle(this);
m_slider = new KisColorSelectorSimple(this);
......@@ -334,12 +334,8 @@ void KisColorSelector::init()
// a tablet can send many more signals, than a mouse
// this causes many repaints, if updating after every signal.
// a workaround with a timer can fix that.
m_updateTimer = new QTimer(this);
m_updateTimer->setInterval(1);
m_updateTimer->setSingleShot(true);
connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(update()));
m_signalCompressor = new KisSignalCompressor(20, KisSignalCompressor::FIRST_INACTIVE, this);
connect(m_signalCompressor, SIGNAL(timeout()), SLOT(update()));
setMinimumSize(40, 40);
}