Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Blackbeard (alberto flores)
Krita
Commits
065ac9ba
Commit
065ac9ba
authored
Jul 17, 2019
by
Blackbeard (alberto flores)
🚢
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added a parasite helper class.
parent
7e087bd6
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
259 additions
and
355 deletions
+259
-355
libs/brush/CMakeLists.txt
libs/brush/CMakeLists.txt
+1
-0
libs/brush/kis_animated_brushes.cpp
libs/brush/kis_animated_brushes.cpp
+0
-85
libs/brush/kis_vectoranimated_brush.cpp
libs/brush/kis_vectoranimated_brush.cpp
+58
-137
libs/brush/kis_vectoranimated_brush.h
libs/brush/kis_vectoranimated_brush.h
+17
-133
libs/brush/kis_vectorbrush_parasite.cpp
libs/brush/kis_vectorbrush_parasite.cpp
+123
-0
libs/brush/kis_vectorbrush_parasite.h
libs/brush/kis_vectorbrush_parasite.h
+60
-0
No files found.
libs/brush/CMakeLists.txt
View file @
065ac9ba
...
...
@@ -20,6 +20,7 @@ set(kritalibbrush_LIB_SRCS
kis_png_brush.cpp
kis_svg_brush.cpp
kis_vectoranimated_brush.cpp
kis_vectorbrush_parasite.cpp
kis_qimage_pyramid.cpp
KisSharedQImagePyramid.cpp
kis_text_brush.cpp
...
...
libs/brush/kis_animated_brushes.cpp
deleted
100644 → 0
View file @
7e087bd6
/*
* Copyright (c) 2012 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.
*/
#include <QRandomGenerator>
#include <kis_animated_brushes.h>
#include <kis_brushes_pipe.h>
#include <kis_vectoranimated_brush.h>
KisAnimatedBrushes
::
KisAnimatedBrushes
()
:
m_isInitialized
(
false
)
{
}
int
KisAnimatedBrushes
::
chooseNextBrush
(
const
KisPaintInformation
&
info
)
{
int
index
;
if
(
!
m_isInitialized
)
{
index
=
0
;
updateBrushIndexes
(
info
,
0
);
m_isInitialized
=
true
;
}
else
{
index
=
KisAnimatedBrushes
::
nextBrushSequence
(
m_currentIndex
,
m_numberOfImages
)
}
m_currentIndex
=
index
;
return
index
;
}
*/
int
KisAnimatedBrushes
::
nextBrushSequence
(
int
currentIndex
,
int
numberOfImages
)
{
if
(
currentIndex
==
numberOfImages
)
{
return
0
;
}
else
{
return
currentIndex
++
;
}
}
int
KisAnimatedBrushes
::
nextBrushRandom
(
int
currentIndex
,
int
numberOfImages
)
{
int
index
=
rand
()
%
numberOfImages
+
1
;
if
(
currentIndex
==
index
)
{
index
=
rand
()
%
numberOfImages
+
1
;
}
return
index
;
}
void
updateBrushIndexes
(
const
KisPaintInformation
&
info
,
int
seqNo
)
override
{
for
(
int
i
=
0
;
i
<
m_parasite
.
dim
;
i
++
)
{
m_parasite
.
index
[
i
]
=
selectPost
(
m_parasite
.
selection
[
i
],
m_parasite
.
index
[
i
],
m_parasite
.
rank
[
i
],
info
,
seqNo
);
}
libs/brush/kis_vectoranimated_brush.cpp
View file @
065ac9ba
/*
* Copyright (c) 201
0 Cyrille B
er
g
er <
cberger@cberger.net
>
/*
* Copyright (c) 201
9 Alberto Eleuterio Flores Gu
er
r
er
o
<
barbanegra+bugs@posteo.mx
>
*
* 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
* the Free Software Foundation; either version
3
of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
...
...
@@ -30,34 +30,26 @@
#include <KoShapePainter.h>
#include <kis_brushes_pipe.h>
#include <kis_vectorbrush_parasite.h>
#include <QDebug>
KisVectorAnimatedBrush
::
KisVectorAnimatedBrush
(
const
QString
&
filename
)
:
KisScalingSizeBrush
(
filename
)
/* , m_imageNumber(0)
, m_isInitialized(false) */
:
KisScalingSizeBrush
(
filename
)
{
setBrushType
(
INVALID
);
setBrushType
(
PIPE_MASK
);
setSpacing
(
0.25
);
setHasColor
(
false
);
/*
if (!m_isInitialized) {
if (m_imageNumber == m_numberOfImages) {
m_imageNumber = 0;
qDebug() << "m_imageNumber" << m_imageNumber;
} else {
m_imageNumber ++;
qDebug() << "m_imageNumber" << m_imageNumber;
}
} */
}
KisVectorAnimatedBrush
::
KisVectorAnimatedBrush
(
const
KisVectorAnimatedBrush
&
rhs
)
:
KisScalingSizeBrush
(
rhs
)
,
m_svg
(
rhs
.
m_svg
)
,
m_svg
(
rhs
.
m_svg
)
{
}
KisBrush
*
KisVectorAnimatedBrush
::
clone
()
const
{
return
new
KisVectorAnimatedBrush
(
*
this
);
...
...
@@ -78,106 +70,16 @@ bool KisVectorAnimatedBrush::load()
return
res
;
}
KisVectorBrushParasite
KisVectorAnimatedBrush
::
m_parasite
;
bool
KisVectorAnimatedBrush
::
loadFromDevice
(
QIODevice
*
dev
)
{
m_svg
=
dev
->
readAll
();
KoXmlDocument
documento
=
SvgParser
::
createDocumentFromSvg
(
m_svg
);
// qDebug() << "ejemplo" << documento.toString();
KoXmlElement
elementos
=
documento
.
documentElement
();
/* qDebug() << documento.toString();
qDebug() << elementos.text(); */
KoDocumentResourceManager
manager
;
SvgParser
parser
(
&
manager
);
parser
.
setResolution
(
QRectF
(
0
,
0
,
100
,
100
),
72
);
// initialize with default values
QSizeF
fragmentSize
;
// QList<KoShape*> shapes = parser.parseSvg(documento.documentElement(), &fragmentSize);
QList
<
KoShape
*>
list
=
parser
.
parseSvg
(
elementos
,
&
fragmentSize
);
/* // According to documentation it is better to use const_iterator if we won't change the QList elements
QList<KoShape*>::const_iterator i;
for (i = list.constBegin(); i != list.constEnd(); ++i)
qDebug() << "figura" << *i;
// qDebug() << list.at(*i) ;
for (int i = 0; i != list.size(); ++i) {
qDebug() << "figura" << i;
qDebug() << list.at(i);
}
*/
m_imageNumber
=
0
;
qDebug
()
<<
"Numero:"
<<
m_imageNumber
;
QList
<
KoShape
*>
single
;
single
.
append
(
list
.
at
(
m_imageNumber
));
qDebug
()
<<
"lista"
<<
list
.
count
();
qDebug
()
<<
"figura"
<<
m_imageNumber
<<
list
.
at
(
m_imageNumber
);
/*
if (m_imageNumber == list.size()) {
m_imageNumber = 0;
}
else {
m_imageNumber ++;
}
*/
m_numberOfImages
=
list
.
size
();
m_isInitialized
=
true
;
// qDebug() << "numberImages" << m_numberOfImages << "initialized" << m_isInitialized << "numero" << m_imageNumber ;
KoShapePainter
painter
;
painter
.
setShapes
(
single
);
QImage
theImage
(
1000
,
1000
,
QImage
::
Format_ARGB32
);
//fix size
{
QPainter
p
(
&
theImage
);
p
.
fillRect
(
0
,
0
,
theImage
.
width
(),
theImage
.
height
(),
Qt
::
white
);
}
painter
.
paint
(
theImage
);
theImage
.
save
(
"my_testImage"
,
"PNG"
);
//should save only one image
/* qDebug() << "shapes" << list[0]; */
// ------------------------------------------- old ------------------------
/* QSvgRenderer renderer(m_svg);
QRect box = renderer.viewBox();
if (box.isEmpty()) return false;
QImage image_(1000, (1000 * box.height()) / box.width(), QImage::Format_ARGB32);
{
QPainter p(&image_);
p.fillRect(0, 0, image_.width(), image_.height(), Qt::white);
renderer.render(&p);
}
*/
// ------------------------------------------- old ------------------------
m_parasite
.
parseSvg
(
m_svg
);
m_parasite
.
setIndex
(
0
);
setBrushTipImage
(
m_parasite
.
nextBrushTip
());
QVector
<
QRgb
>
table
;
for
(
int
i
=
0
;
i
<
256
;
++
i
)
table
.
push_back
(
qRgb
(
i
,
i
,
i
));
theImage
=
theImage
.
convertToFormat
(
QImage
::
Format_Indexed8
,
table
);
setBrushTipImage
(
theImage
);
// Blackbeard TODO!!
// KoCanvasControllerWidgetViewport_p.cpp
// KoSvgSymbolCollectionResource.cpp
// KoShapePainter.cpp --> boud told me to check this library
// SvgWriter.cpp line 256
// KoMarker.cpp line 99
// setBrushTipImage(theImage);
// > couldn't you just set a single shape with void setShapes(const
// QList<KoShape*> &shapes); ?
setValid
(
true
);
...
...
@@ -196,9 +98,10 @@ bool KisVectorAnimatedBrush::loadFromDevice(QIODevice *dev)
QFileInfo
fi
(
filename
());
setName
(
fi
.
baseName
());
return
!
brushTipImage
().
isNull
()
&&
valid
();
return
!
brushTipImage
().
isNull
()
&&
valid
();
}
bool
KisVectorAnimatedBrush
::
save
()
{
QFile
f
(
filename
());
...
...
@@ -229,43 +132,61 @@ void KisVectorAnimatedBrush::toXML(QDomDocument& d, QDomElement& e) const
}
/*
// <---------------------- Index Functions -------------------->
void KisAnimatedBrushes::notifyStrokeStarted() {
m_isInitialized = false
;
void
KisVectorAnimatedBrush
::
prepareForSeqNo
(
const
KisPaintInformation
&
info
,
int
seqNo
)
{
Q_UNUSED
(
info
)
Q_UNUSED
(
seqNo
)
m_parasite
.
nextIndex
();
newbrushTip
()
;
}
void KisAnimatedBrush
es
::n
otifyCachedDabPainted(const KisPaintInformation& info
)
void
Kis
Vector
AnimatedBrush
::
n
ewbrushTip
(
)
{
m_d->brushesPipe.notifyCachedDabPainted(info);
}
QImage
image
=
m_parasite
.
nextBrushTip
();
void KisAnimatedBrushes::prepareForSeqNo(const KisPaintInformation &info, int seqNo)
{
m_d->brushesPipe.prepareForSeqNo(info, seqNo);
}
setBrushTipImage
(
image
);
setValid
(
true
);
// Well for now, always true
if
(
brushTipImage
().
isGrayscale
())
{
setBrushType
(
MASK
);
setHasColor
(
false
);
}
else
{
setBrushType
(
IMAGE
);
setHasColor
(
true
);
}
enumBrushType KisAnimatedBrushes::brushType() const
{
return !hasColor() || useColorAsMask() ? PIPE_MASK : PIPE_IMAGE;
}
setWidth
(
brushTipImage
().
width
());
setHeight
(
brushTipImage
().
height
());
bool KisAnimatedBrushes::hasColor() const
{
return m_d->brushesPipe.hasColor();
}
quint32 KisAnimatedBrushes::brushIndex(const KisPaintInformation& info) const
/*
KisFixedPaintDeviceSP KisVectorAnimatedBrush::paintDevice(const KoColorSpace *colorSpace,
const KisDabShape &,
const KisPaintInformation &info,
double subPixelX, double subPixelY) const
{
return m_d->brushesPipe.brushIndex(info);
}
Q_ASSERT(valid());
Q_UNUSED(info)
Q_UNUSED(subPixelX)
Q_UNUSED(subPixelY)
qDebug() << m_imageNumber;
nextIndex();
m_imageNumber++;
QImage outputImage = m_brushTip;
KisFixedPaintDeviceSP dab = new KisFixedPaintDevice(colorSpace);
Q_CHECK_PTR(dab);
dab->convertFromQImage(outputImage, "");
return dab;
}
*/
libs/brush/kis_vectoranimated_brush.h
View file @
065ac9ba
/*
* Copyright (c) 201
0 Cyrille B
er
g
er <
cberger@cberger.net
>
* Copyright (c) 201
9 Alberto Eleuterio Flores Gu
er
r
er
o
<
barbanegra+bugs@posteo.mx
>
*
* 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
* the Free Software Foundation; either version
3
of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
...
...
@@ -25,11 +25,15 @@
#include <KoShapePainter.h>
#include <SvgParser.h>
#include <KoXmlReader.h>
#include <kis_vectorbrush_parasite.h>
//
class
BRUSH_EXPORT
KisVectorAnimatedBrush
:
public
KisScalingSizeBrush
{
public:
/// Construct brush to load filename later as brush
KisVectorAnimatedBrush
(
const
QString
&
filename
);
KisVectorAnimatedBrush
(
const
KisVectorAnimatedBrush
&
rhs
);
...
...
@@ -42,144 +46,24 @@ public:
QString
defaultFileExtension
()
const
override
;
void
toXML
(
QDomDocument
&
d
,
QDomElement
&
e
)
const
override
;
/*
// <------------------------------------------------- Draft Data -------------------------------------------------------->
//type of Brush
namespace KisAnimated
{
enum SelectionMode {
Sequence,
Random
};
}
// State of the brush
bool m_isInitialized;
// style of brush
// "Sequence"
// "Random"
QString m_brushStyle;
//Needed to parse the svg
KoXmlDocument m_document;
KoXmlElement m_elements;
// QList with all the brush tips
QList<KoShape*> m_listOfTips;
// The index of the QList to get the proper QImage
quint32 m_listIndex;
// Current Size of the list of QList
int m_listSize;
// Current brush tip
QImage m_brushTip;
// <------------------------------------------------- Draft Functions -------------------------------------------------------->
// <------------------------ Initialize Functions ----------------------------->
// bool -> bool
// tells if brush is Initialized
bool isBrushInitialized();
// <------------------------ Metadata Functions ----------------------------->
// svg -> QString
// Returns the style of the brush
QString getBrushStyle();
// KoXmlDocument -> QList
//helper for getBrushStyle
// returns the metadata of the brush in a QList
QList<QString> getMetadata();
// QList -> QString
// helper for getBrushStyle
// Returns Style of the brush : "Random", "Sequence"
QString getMetadataStyle();
// <------------------------ List of Shapes Functions ----------------------------->
// svg -> QList<KoShape*>
// Returns the shapes of the SVG
QList<KoShape*> getBrushShapes();
// <------------------------ B
rush
Tip
Functions ----------------------------->
void
newb
rushTip
();
// QList<KoShape*> int -> QImage
// Returns the proper QImage
QImage getBrushStamp();
// QList<KoShape*> int -> QImage
// Returns the proper QImage
QImage setBrushStamp();
void setAngle(qreal angle) override;
void setScale(qreal scale) override;
void setSpacing(double spacing) override;
// <------------------------ Index Functions ----------------------------->
//KisPaintInformation -> quint32
// Returns current Index
quint32 brushIndex(const KisPaintInformation& info) const override;
// KisPaintInformation -> int
// Returns and index for the next brush
int chooseNextBrush(const KisPaintInformation& info) override;
// int -> int
// helper for chooseNextBrush
// Returns next index in sequence
int nextBrushSequence();
// int -> int
// helper for chooseNextBrush
// Returns a random index
int nextBrushRandom();
// qint32 maskWidth(KisDabShape const&, double subPixelX, double subPixelY, const KisPaintInformation& info) const override;
// qint32 maskHeight(KisDabShape const&, double subPixelX, double subPixelY, const KisPaintInformation& info) const override;
void notifyStrokeStarted() override;
void notifyCachedDabPainted(const KisPaintInformation& info) override;
// void notifyStrokeStarted() override;
// void notifyCachedDabPainted(const KisPaintInformation& info) override;
void
prepareForSeqNo
(
const
KisPaintInformation
&
info
,
int
seqNo
)
override
;
protected:
void setBrushType(enumBrushType type) override;
// private:
// friend class KisAnimatedBrushesTest;
// KisVectorAnimatedBrush* testingGetCurrentBrush(const KisPaintInformation& info) const;
// void testingSelectNextBrush(const KisPaintInformation& info) const;
/*
// Asks for the new image
KisFixedPaintDeviceSP paintDevice(const KoColorSpace * colorSpace,
KisDabShape const&,
const KisPaintInformation& info,
double subPixelX = 0, double subPixelY = 0) const override;
*/
private:
QByteArray
m_svg
;
int
m_imageNumber
;
int
m_numberOfImages
;
bool
m_isInitialized
;
static
KisVectorBrushParasite
m_parasite
;
/* struct Private;
Private * const m_d; */
...
...
libs/brush/kis_vectorbrush_parasite.cpp
0 → 100644
View file @
065ac9ba
/*
* Copyright (c) 2019 Alberto Eleuterio Flores Guerrero <barbanegra+bugs@posteo.mx>
*
* 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 3 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_vectorbrush_parasite.h"
#include <KoShapeManager.h>
#include <SvgParser.h>
#include <KoDocumentResourceManager.h>
#include <KoXmlReader.h>
#include <KoShapePainter.h>
#include <QDebug>
KisVectorBrushParasite
::
KisVectorBrushParasite
()
{
}
void
KisVectorBrushParasite
::
parseSvg
(
QByteArray
svg
)
{
m_shapes
=
svgToKoShapes
(
svg
);
m_maxIndex
=
m_shapes
.
size
();
}
QList
<
KoShape
*>
KisVectorBrushParasite
::
svgToKoShapes
(
QByteArray
svg
)
{
KoXmlDocument
document
=
SvgParser
::
createDocumentFromSvg
(
svg
);
// qDebug() << "document" << documento.toString();
KoXmlElement
elements
=
document
.
documentElement
();
// qDebug() << element.text();
// Necessary to parse the elemnts
KoDocumentResourceManager
manager
;
SvgParser
parser
(
&
manager
);
parser
.
setResolution
(
QRectF
(
0
,
0
,
100
,
100
),
72
);
// initialize with default values
QSizeF
fragmentSize
;
QList
<
KoShape
*>
shapes
=
parser
.
parseSvg
(
elements
,
&
fragmentSize
);
return
shapes
;
}
// Blackbeard TODO!!
// KoCanvasControllerWidgetViewport_p.cpp
// KoSvgSymbolCollectionResource.cpp
// KoShapePainter.cpp --> boud told me to check this library
// SvgWriter.cpp line 256
// KoMarker.cpp line 99
// setBrushTipImage(theImage);
// > couldn't you just set a single shape with void setShapes(const
// QList<KoShape*> &shapes); ?
// this is too expensive, should be done with KoShapeManager
QImage
KisVectorBrushParasite
::
shapeToQImage
(
QList
<
KoShape
*>
shapes
,
int
index
)
{
QList
<
KoShape
*>
single_list
;
single_list
.
append
(
shapes
.
at
(
index
));
KoShapePainter
painter
;
painter
.
setShapes
(
single_list
);
QImage
theImage
(
1000
,
1000
,
QImage
::
Format_ARGB32
);
//fix size
{
QPainter
p
(
&
theImage
);
p
.
fillRect
(
0
,
0
,
theImage
.
width
(),
theImage
.
height
(),
Qt
::
white
);
}
painter
.
paint
(
theImage
);
QVector
<
QRgb
>
table
;
for
(
int
i
=
0
;
i
<
256
;
++
i
)
table
.
push_back
(
qRgb
(
i
,
i
,
i
));