Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_normal_preview_widget.cpp
Go to the documentation of this file.
1/* This file is part of the KDE project
2 *
3 * SPDX-FileCopyrightText: 2015 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com>
4 *
5 * SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7
9#include <cmath>
10#include <QColor>
11#include <QPoint>
12
13#include "kis_global.h"
14#include <KoResourcePaths.h>
15
17 : QLabel(parent)
18{
19 m_redChannel = 0;
21 m_blueChannel = 4;
22 //TODO: this can be changed in frameworks to KoResourcePaths::findResource("kis_images", "krita-tangentnormal.png");
23 m_fileName = KoResourcePaths::findAsset("kis_images", "krita-tangentnormal-preview.png");
24 QImage preview = QImage(m_fileName);
25 setPixmap(QPixmap::fromImage(preview.scaled(200, 200, Qt::KeepAspectRatio, Qt::SmoothTransformation)));
26}
27
31
33{
34 if (index>=0 && index<6){
35 m_redChannel=index;
36 }
38}
39
41{
42 if (index>=0 && index<6){
43 m_greenChannel=index;
44 }
46}
47
49{
50 if (index>=0 && index<6){
51 m_blueChannel=index;
52 }
54}
55
57{
58 QImage preview = QImage(m_fileName);
59 preview = swizzleTransformPreview (preview);
60 setPixmap(QPixmap::fromImage(preview.scaled(200, 200, Qt::KeepAspectRatio, Qt::SmoothTransformation)));
61 repaint();
62}
63
65{
66 int width = preview.width();
67 int height = preview.height();
68 QImage endPreview(preview.width(),preview.height(),QImage::Format_RGB32);
69 for (int y=0; y<height; y++) {
70 for (int x=0; x<width; x++) {
71 QColor currentcolor = QColor(preview.pixel(x,y));
72 int r, g, b =0;
73 r = previewTransform(currentcolor.red(), currentcolor.green(), currentcolor.blue(), m_redChannel, 255);
74 g = previewTransform(currentcolor.red(), currentcolor.green(), currentcolor.blue(), m_greenChannel, 255);
75 b = previewTransform(currentcolor.red(), currentcolor.green(), currentcolor.blue(), m_blueChannel, 255);
76 QRgb transformedColor = qRgb(r,g,b);
77 endPreview.setPixel(x,y, transformedColor);
78 }
79 }
80 return endPreview;
81}
82
83int KisNormalPreviewWidget::previewTransform(int const horizontal, int const vertical, int const depth, int index, int maxvalue)
84{
85 int component = 0;
86 switch(index) {
87 case 0: component = horizontal; break;
88 case 1: component = maxvalue-horizontal; break;
89 case 2: component = vertical; break;
90 case 3: component = maxvalue-vertical; break;
91 case 4: component = depth; break;
92 case 5: component = maxvalue-depth; break;
93 }
94 return component;
95}
QImage swizzleTransformPreview(QImage preview)
int previewTransform(int const horizontal, int const vertical, int const depth, int index, int maxvalue)
KisNormalPreviewWidget(QWidget *parent=0)
static QString findAsset(const QString &type, const QString &fileName)
unsigned int QRgb