Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_image.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2002 Patrick Julien <freak@codepimps.org>
3 * SPDX-FileCopyrightText: 2007 Boudewijn Rempt <boud@valdyas.org>
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 */
7#ifndef KIS_IMAGE_H_
8#define KIS_IMAGE_H_
9
10#include <QObject>
11#include <QString>
12#include <QPainter>
13#include <QRect>
14
16
17#include "kis_types.h"
18#include "kis_shared.h"
20#include "kis_node_facade.h"
23#include "KisLodPreferences.h"
24#include "KisWraparoundAxis.h"
25
26#include <kritaimage_export.h>
27
28class KoColorSpace;
29class KoColor;
30
32class KisUndoStore;
33class KisUndoAdapter;
37class KoColorProfile;
43class KisPaintDevice;
45
46namespace KisMetaData
47{
48class MergeStrategy;
49}
50
56class KRITAIMAGE_EXPORT KisImage : public QObject,
57 public KisStrokesFacade,
59 public KisUpdatesFacade,
61 public KisNodeFacade,
63 public KisShared
64{
65
66 Q_OBJECT
67
68public:
70 KisImage(KisUndoStore *undoStore, qint32 width, qint32 height, const KoColorSpace *colorSpace, const QString& name);
71 ~KisImage() override;
72
73 static KisImageSP fromQImage(const QImage &image, KisUndoStore *undoStore);
74
75public: // KisNodeGraphListener implementation
76
77 void aboutToAddANode(KisNode *parent, int index) override;
78 void nodeHasBeenAdded(KisNode *parent, int index, KisNodeAdditionFlags flags) override;
79 void aboutToRemoveANode(KisNode *parent, int index) override;
80 void nodeChanged(KisNode * node) override;
81 void nodeCollapsedChanged(KisNode *node) override;
82 void invalidateAllFrames() override;
83 void notifySelectionChanged() override;
84 void requestProjectionUpdate(KisNode *node, const QVector<QRect> &rects, KisProjectionUpdateFlags flags) override;
85 void invalidateFrames(const KisTimeSpan &range, const QRect &rect) override;
86 void requestTimeSwitch(int time) override;
87 KisNode* graphOverlayNode() const override;
88
89 void keyframeChannelHasBeenAdded(KisNode *node, KisKeyframeChannel *channel) override;
90 void keyframeChannelAboutToBeRemoved(KisNode *node, KisKeyframeChannel *channel) override;
91
92public: // KisProjectionUpdateListener implementation
93 void notifyProjectionUpdated(const QRect &rc) override;
94
95public:
96
100 void setWorkingThreadsLimit(int value);
101
105 int workingThreadsLimit() const;
106
117 KisImage *clone(bool exactCopy = false);
118
119 void copyFromImage(const KisImage &rhs);
120
121private:
122
123 // must specify exactly one from CONSTRUCT or REPLACE.
125 CONSTRUCT = 1,
126 REPLACE = 2,
127 EXACT_COPY = 4,
128 };
129
130 void copyFromImageImpl(const KisImage &rhs, int policy);
131
132public:
133
137 QImage convertToQImage(qint32 x1,
138 qint32 y1,
139 qint32 width,
140 qint32 height,
141 const KoColorProfile * profile);
142
147 QImage convertToQImage(QRect imageRect,
148 const KoColorProfile * profile);
149
150
154 QImage convertToQImage(const QSize& scaledImageSize, const KoColorProfile *profile);
155
173 void immediateLockForReadOnly();
174
180 void unlock();
181
190 bool locked() const;
191
197 void setOverlaySelectionMask(KisSelectionMaskSP mask);
198
202 KisSelectionMaskSP overlaySelectionMask() const;
203
207 bool hasOverlaySelectionMask() const;
208
213 KisSelectionSP globalSelection() const;
214
218 QString nextLayerName(const QString &baseName = "") const;
219
235 void resizeImage(const QRect& newRect);
236
251 void cropImage(const QRect& newRect);
252
260 void purgeUnusedData(bool isCancellable);
261
276 void cropNode(KisNodeSP node, const QRect& newRect, const bool activeFrameOnly = false);
277 void cropNodes(KisNodeList nodes, const QRect& newRect, const bool activeFrameOnly = false);
278
290 void scaleImage(const QSize &size, qreal xres, qreal yres, KisFilterStrategy *filterStrategy);
291
305 void scaleNode(KisNodeSP node, const QPointF &center, qreal scaleX, qreal scaleY, KisFilterStrategy *filterStrategy, KisSelectionSP selection);
306 void scaleNodes(KisNodeList nodes, const QPointF &center, qreal scaleX, qreal scaleY, KisFilterStrategy *filterStrategy, KisSelectionSP selection);
307
319 void rotateImage(double radians);
320
334 void rotateNode(KisNodeSP node, double radians, KisSelectionSP selection);
335 void rotateNodes(KisNodeList nodes, double radians, KisSelectionSP selection);
336
348 void shear(double angleX, double angleY);
349
364 void shearNode(KisNodeSP node, double angleX, double angleY, KisSelectionSP selection);
365 void shearNodes(KisNodeList nodes, double angleX, double angleY, KisSelectionSP selection);
366
370 void convertImageProjectionColorSpace(const KoColorSpace *dstColorSpace);
371
375 void convertImageColorSpace(const KoColorSpace *dstColorSpace,
377 KoColorConversionTransformation::ConversionFlags conversionFlags);
378
385 void unifyLayersColorSpace();
386
390 void convertLayerColorSpace(KisNodeSP node,
391 const KoColorSpace *dstColorSpace,
393 KoColorConversionTransformation::ConversionFlags conversionFlags);
394
395
396 // Get the profile associated with this image
397 const KoColorProfile * profile() const;
398
408 bool assignLayerProfile(KisNodeSP node, const KoColorProfile *profile);
409
420 bool assignImageProfile(const KoColorProfile *profile, bool blockAllUpdates = false);
421
429 KisUndoAdapter* undoAdapter() const;
430
438
443 const KUndo2Command* lastExecutedCommand() const override;
444
451 void setUndoStore(KisUndoStore *undoStore);
452
456 KisUndoStore* undoStore();
457
468 void setModifiedWithoutUndo();
469
474 const KoColorSpace * colorSpace() const;
475
479 double xRes() const;
480
484 double yRes() const;
485
489 void setResolution(double xres, double yres);
490
496 QPointF documentToPixel(const QPointF &documentCoord) const;
497
503 QPoint documentToImagePixelFloored(const QPointF &documentCoord) const;
504
510 QRectF documentToPixel(const QRectF &documentRect) const;
511
517 QPointF pixelToDocument(const QPointF &pixelCoord) const;
518
525 QPointF pixelToDocument(const QPoint &pixelCoord) const;
526
532 QRectF pixelToDocument(const QRectF &pixelCoord) const;
533
537 qint32 width() const;
538
542 qint32 height() const;
543
547 QSize size() const {
548 return QSize(width(), height());
549 }
550
554 KisGroupLayerSP rootLayer() const;
555
560 KisPaintDeviceSP projection() const;
561
566 qint32 nlayers() const;
567
572 qint32 nHiddenLayers() const;
573
574 /*
575 * Return the number of layers (not other node types) that are
576 * descendants of the rootLayer in this image.
577 */
578 qint32 nChildLayers() const;
579
583 void flatten(KisNodeSP activeNode);
584
589 void mergeDown(KisLayerSP l, const KisMetaData::MergeStrategy* strategy);
590
596 void flattenLayer(KisLayerSP layer);
597
602 void mergeMultipleLayers(QList<KisNodeSP> mergedLayers, KisNodeSP putAfter);
603
605 QRect bounds() const override;
606
612 QRect effectiveLodBounds() const;
613
615 void notifyLayersChanged();
616
621 void setDefaultProjectionColor(const KoColor &color);
622
626 KoColor defaultProjectionColor() const;
627
628 void setRootLayer(KisGroupLayerSP rootLayer);
629
635 void addAnnotation(KisAnnotationSP annotation);
636
638 KisAnnotationSP annotation(const QString& type);
639
641 void removeAnnotation(const QString& type);
642
646 vKisAnnotationSP_it beginAnnotations();
647
649 vKisAnnotationSP_it endAnnotations();
650
654 void notifyAboutToBeDeleted();
655
656 KisImageSignalRouter* signalRouter();
657
663 bool canReselectGlobalSelection();
664
668 QList<KisLayerCompositionSP> compositions();
669
673 void addComposition(KisLayerCompositionSP composition);
674
678 void removeComposition(KisLayerCompositionSP composition);
679
683 void moveCompositionUp(KisLayerCompositionSP composition);
684
688 void moveCompositionDown(KisLayerCompositionSP composition);
689
697 void setWrapAroundModePermitted(bool value);
698
707 bool wrapAroundModePermitted() const;
708
712 void setWrapAroundModeAxis(WrapAroundAxis value);
718 WrapAroundAxis wrapAroundModeAxis() const;
719
720
727 bool wrapAroundModeActive() const;
728
734 int currentLevelOfDetail() const;
735
741 QPointF mirrorAxesCenter() const;
742
747 void setMirrorAxesCenter(const QPointF &value) const;
748
754 void setAllowMasksOnRootNode(bool value);
755
759 bool allowMasksOnRootNode() const;
760
761public Q_SLOTS:
762
768 void explicitRegenerateLevelOfDetail();
769
770public:
771
777 void setLodPreferences(const KisLodPreferences &value);
778
785 KisLodPreferences lodPreferences() const;
786
787 KisImageAnimationInterface *animationInterface() const;
788
794 void setProofingConfiguration(KisProofingConfigurationSP proofingConfig);
799 KisProofingConfigurationSP proofingConfiguration() const;
800
801
802 bool startIsolatedMode(KisNodeSP node, bool isolateLayer, bool isolateGroup);
803
804public Q_SLOTS:
805 void stopIsolatedMode();
806
807public:
808 KisNodeSP isolationRootNode() const;
809 bool isIsolatingLayer() const;
810 bool isIsolatingGroup() const;
811
812Q_SIGNALS:
813
818 void sigImageUpdated(const QRect &);
819
825
831
848 void sigSizeChanged(const QPointF &oldStillPoint, const QPointF &newStillPoint);
849
850 void sigProfileChanged(const KoColorProfile * profile);
852 void sigResolutionChanged(double xRes, double yRes);
853 void sigRequestNodeReselection(KisNodeSP activeNode, const KisNodeList &selectedNodes);
854
859
864
877 void sigNodeAddedAsync(KisNodeSP node, KisNodeAdditionFlags flags);
878
889
897
909
918
931
944
950
959
965
971
977
978public:
979 KisCompositeProgressProxy* compositeProgressProxy();
980
981 bool isIdle(bool allowLocked = false);
982
999 void barrierLock(bool readOnly = false);
1000
1011 bool tryBarrierLock(bool readOnly = false);
1012
1018 void waitForDone();
1019
1020 KisStrokeId startStroke(KisStrokeStrategy *strokeStrategy) override;
1021 void addJob(KisStrokeId id, KisStrokeJobData *data) override;
1022 void endStroke(KisStrokeId id) override;
1023 bool cancelStroke(KisStrokeId id) override;
1024
1028 void blockUpdates() override;
1029
1034 void unblockUpdates() override;
1035
1046 void disableUIUpdates() override;
1047
1053 void notifyBatchUpdateStarted() override;
1054
1059 void notifyBatchUpdateEnded() override;
1060
1069 void notifyUIUpdateCompleted(const QRect &rc) override;
1070
1075
1093 void disableDirtyRequests() override;
1094
1098 void enableDirtyRequests() override;
1099
1124
1139
1146
1148 void refreshGraphAsync(KisNodeSP root, const QVector<QRect> &rects, const QRect &cropRect, KisProjectionUpdateFlags flags = KisProjectionUpdateFlag::None) override;
1149
1158 void initialRefreshGraph();
1159
1167 void addSpontaneousJob(KisSpontaneousJob *spontaneousJob);
1168
1175 bool hasUpdatesRunning() const override;
1176
1177public Q_SLOTS:
1178
1189 void requestUndoDuringStroke();
1190
1201 void requestRedoDuringStroke();
1202
1212 void requestStrokeCancellation();
1213
1221 UndoResult tryUndoUnfinishedLod0Stroke();
1222
1229 void requestStrokeEnd();
1230
1238 void requestStrokeEndActiveNode();
1239
1243 KisImageGlobalSelectionManagementInterface* globalSelectionManagementInterface() const;
1244
1245private:
1246
1247 KisImage(const KisImage& rhs, KisUndoStore *undoStore, bool exactCopy);
1249
1251
1252 void resizeImageImpl(const QRect& newRect, bool cropLayers);
1253 void rotateImpl(const KUndo2MagicString &actionName, KisNodeSP rootNode, double radians,
1254 bool resizeImage, KisSelectionSP selection);
1255 void rotateImpl(const KUndo2MagicString &actionName, KisNodeList nodes, double radians,
1256 bool resizeImage, KisSelectionSP selection);
1257 void shearImpl(const KUndo2MagicString &actionName, KisNodeSP rootNode,
1258 bool resizeImage, double angleX, double angleY, KisSelectionSP selection);
1259 void shearImpl(const KUndo2MagicString &actionName, KisNodeList nodes,
1260 bool resizeImage, double angleX, double angleY, KisSelectionSP selection);
1261
1263
1264 void refreshHiddenArea(KisNodeSP rootNode, const QRect &preparedArea);
1265
1267 void setSize(const QSize& size);
1268
1269 void setProjectionColorSpace(const KoColorSpace * colorSpace);
1270
1272
1273private:
1274 class KisImagePrivate;
1276};
1277
1278#endif // KIS_IMAGE_H_
float value(const T *src, size_t ch)
WrapAroundAxis
void sigLayersChangedAsync()
void refreshHiddenArea(KisNodeSP rootNode, const QRect &preparedArea)
void sigNodeCollapsedChanged()
KisImagePrivate * m_d
Definition kis_image.h:1275
void sigProfileChanged(const KoColorProfile *profile)
void emitSizeChanged()
void sigRequestNodeReselection(KisNodeSP activeNode, const KisNodeList &selectedNodes)
void sigStrokeCancellationRequested()
void sigRedoDuringStrokeRequested()
void sigImageModified()
void sigInternalStopIsolatedModeRequested()
void sigIsolatedModeChanged()
void safeRemoveTwoNodes(KisNodeSP node1, KisNodeSP node2)
void sigRemoveNodeAsync(KisNodeSP node)
void sigResolutionChanged(double xRes, double yRes)
void sigColorSpaceChanged(const KoColorSpace *cs)
QSize size() const
Definition kis_image.h:547
void sigStrokeEndRequested()
void sigUndoDuringStrokeRequested()
void sigNodeChanged(KisNodeSP node)
void sigAboutToBeDeleted()
void sigStrokeEndRequestedActiveNodeFiltered()
void cropNodes(KisNodeList nodes, const QRect &newRect, const bool activeFrameOnly=false)
void sigImageModifiedWithoutUndo()
void sigProofingConfigChanged()
void sigImageUpdated(const QRect &)
void sigNodeAddedAsync(KisNodeSP node, KisNodeAdditionFlags flags)
KisImage & operator=(const KisImage &rhs)
void sigSizeChanged(const QPointF &oldStillPoint, const QPointF &newStillPoint)
KisKeyframeChannel stores and manages KisKeyframes. Maps units of time to virtual keyframe values....
virtual void notifyProjectionUpdated(const QRect &rc)=0
The KisProofingConfiguration struct Little struct that stores the proofing configuration for a given ...
virtual const KUndo2Command * lastExecutedCommand() const =0
virtual KisPostExecutionUndoAdapter * postExecutionUndoAdapter() const =0
virtual KisStrokeId startStroke(KisStrokeStrategy *strokeStrategy)=0
virtual void endStroke(KisStrokeId id)=0
virtual void addJob(KisStrokeId id, KisStrokeJobData *data)=0
virtual bool cancelStroke(KisStrokeId id)=0
virtual KisProjectionUpdatesFilterCookie addProjectionUpdatesFilter(KisProjectionUpdatesFilterSP filter)=0
virtual void enableDirtyRequests()=0
virtual void notifyBatchUpdateStarted()=0
virtual void disableDirtyRequests()=0
virtual bool hasUpdatesRunning() const =0
virtual void notifyBatchUpdateEnded()=0
virtual void blockUpdates()=0
virtual KisProjectionUpdatesFilterCookie currentProjectionUpdatesFilter() const =0
virtual KisProjectionUpdatesFilterSP removeProjectionUpdatesFilter(KisProjectionUpdatesFilterCookie cookie)=0
virtual void disableUIUpdates()=0
virtual void notifyUIUpdateCompleted(const QRect &rc)=0
virtual void unblockUpdates()=0
void refreshGraphAsync(KisNodeSP root=nullptr, KisProjectionUpdateFlags flags=KisProjectionUpdateFlag::None)
virtual QVector< QRect > enableUIUpdates()=0
static QImage convertToQImage(char *buffer, qint32 width, qint32 height)
save the QImages as png files to directory image_tests
#define bounds(x, a, b)
vKisAnnotationSP::iterator vKisAnnotationSP_it
Definition kis_types.h:181
void * KisProjectionUpdatesFilterCookie
Definition kis_types.h:285
virtual void keyframeChannelHasBeenAdded(KisNode *node, KisKeyframeChannel *channel)
virtual KisNode * graphOverlayNode() const
virtual void aboutToRemoveANode(KisNode *parent, int index)
virtual void keyframeChannelAboutToBeRemoved(KisNode *node, KisKeyframeChannel *channel)
virtual void aboutToAddANode(KisNode *parent, int index)
virtual void requestProjectionUpdate(KisNode *node, const QVector< QRect > &rects, KisProjectionUpdateFlags flags)
virtual void nodeHasBeenAdded(KisNode *parent, int index, KisNodeAdditionFlags flags)
virtual void nodeChanged(KisNode *node)
virtual void invalidateFrames(const KisTimeSpan &range, const QRect &rect)
virtual void requestTimeSwitch(int time)
virtual void nodeCollapsedChanged(KisNode *node)