Krita Source Code Documentation
Loading...
Searching...
No Matches
KisReferenceImage Class Reference

The KisReferenceImage class represents a single reference image. More...

#include <KisReferenceImage.h>

+ Inheritance diagram for KisReferenceImage:

Classes

struct  Private
 
struct  SetSaturationCommand
 

Public Member Functions

KoShape * cloneShape () const override
 creates a deep copy of the shape or shape's subtree
 
QPointF documentToPixel (const QPointF &docPoint)
 
QPoint documentToPixelFloored (const QPointF &docPoint)
 
bool embed ()
 
QString filename () const
 
QImage getCachedImage ()
 
QImage getImage ()
 
KoColor getPixel (QPointF position)
 
bool hasLocalFile ()
 
QString internalFile () const
 
 KisReferenceImage ()
 
 KisReferenceImage (const KisReferenceImage &rhs)
 
bool loadImage (KoStore *store)
 
void paint (QPainter &gc) const override
 Paint the shape fill The class extending this one is responsible for painting itself. painter is expected to be preconfigured to work in "document" pixels.
 
qreal saturation () const
 
bool saveImage (KoStore *store) const
 
void saveXml (QDomDocument &document, QDomElement &parentElement, int id)
 
void setEmbed (bool embed)
 
void setFilename (const QString &filename)
 
void setSaturation (qreal saturation)
 
 ~KisReferenceImage ()
 
- Public Member Functions inherited from KoShape
QRectF absoluteOutlineRect () const
 
QPointF absolutePosition (KoFlake::AnchorPosition anchor=KoFlake::Center) const
 
QTransform absoluteTransformation () const
 
bool addDependee (KoShape *shape)
 
QString additionalAttribute (const QString &name) const
 
void addShapeChangeListener (ShapeChangeListener *listener)
 
KoShapeAnchor * anchor () const
 
void applyAbsoluteTransformation (const QTransform &matrix)
 
void applyTransformation (const QTransform &matrix)
 
virtual QSharedPointer< KoShapeBackground > background () const
 
virtual QRectF boundingRect () const
 Get the bounding box of the shape.
 
virtual ChildZOrderPolicy childZOrderPolicy ()
 
KoClipMask * clipMask () const
 Returns the currently set clip mask or 0 if there is no clip mask set.
 
KoClipPath * clipPath () const
 Returns the currently set clip path or 0 if there is no clip path set.
 
KoShape * cloneShapeAndBakeAbsoluteTransform () const
 creates a deep copy of the shape/shapes tree and bakes the absolute transform of this into the resulting shape.
 
void copySettings (const KoShape *shape)
 
QList< KoShape * > dependees () const
 Returns list of shapes depending on this shape.
 
QPointF documentToShape (const QPointF &point) const
 Transforms point from document coordinates to shape coordinates.
 
QRectF documentToShape (const QRectF &rect) const
 Transform rect from document coordinates to shape coordinates.
 
bool hasAdditionalAttribute (const QString &name) const
 
bool hasCommonParent (const KoShape *shape) const
 
bool hasDependee (KoShape *shape) const
 Returns if the given shape is dependent on this shape.
 
virtual bool hasTransparency () const
 
virtual bool hitTest (const QPointF &position) const
 Check if the shape is hit on position.
 
QString hyperLink () const
 
bool inheritBackground () const
 inheritBackground shows if the shape inherits background from its parent
 
bool inheritPaintOrder () const
 inheritPaintOrder
 
bool inheritsTransformFromAny (const QList< KoShape * > ancestorsInQuestion) const
 inheritsTransformFromAny checks if the shape inherits transformation from any of the shapes listed in ancestorsInQuestion. The inheritance is checked in recursive way.
 
bool inheritStroke () const
 inheritStroke shows if the shape inherits the stroke from its parent
 
bool isContentProtected () const
 
bool isGeometryProtected () const
 
bool isPrintable () const
 
bool isSelectable () const
 
virtual bool isShapeEditable (bool recursive=true) const
 checks recursively if the shape or one of its parents is not visible or locked
 
bool isVisible (bool recursive=true) const
 
bool keepAspectRatio () const
 
 KoShape ()
 Constructor.
 
qreal minimumHeight () const
 
QString name () const
 
void notifyChanged ()
 
virtual QPainterPath outline () const
 
virtual QRectF outlineRect () const
 
virtual void paintMarkers (QPainter &painter) const
 paintStroke paints the shape's markers
 
virtual QVector< PaintOrder > paintOrder () const
 paintOrder
 
virtual void paintStroke (QPainter &painter) const
 paintStroke paints the shape's stroked outline
 
KoShapeContainer * parent () const
 
QPointF position () const
 Get the position of the shape in pt.
 
void removeAdditionalAttribute (const QString &name)
 
void removeAdditionalStyleAttribute (const char *name)
 
void removeDependee (KoShape *shape)
 
void removeShapeChangeListener (ShapeChangeListener *listener)
 
void rotate (qreal angle)
 Rotate the shape (relative)
 
qreal rotation () const
 
void scale (qreal sx, qreal sy)
 Scale the shape using the zero-point which is the top-left corner.
 
void setAbsolutePosition (const QPointF &newPosition, KoFlake::AnchorPosition anchor=KoFlake::Center)
 
void setAdditionalAttribute (const QString &name, const QString &value)
 
void setAdditionalStyleAttribute (const char *name, const QString &value)
 
void setAnchor (KoShapeAnchor *anchor)
 
virtual void setBackground (QSharedPointer< KoShapeBackground > background)
 
void setClipMask (KoClipMask *clipMask)
 Sets a new clip mask, removing the old one. The mask is owned by the shape.
 
void setClipPath (KoClipPath *clipPath)
 Sets a new clip path, removing the old one.
 
void setContentProtected (bool protect)
 
void setGeometryProtected (bool on)
 
void setHyperLink (const QString &hyperLink)
 
void setInheritBackground (bool value)
 setInheritBackground marks a shape as inheriting the background from the parent shape. NOTE: The currently selected background is destroyed.
 
void setInheritPaintOrder (bool value)
 setInheritPaintOrder set inherit paint order.
 
void setInheritStroke (bool value)
 setInheritStroke marks a shape as inheriting the stroke from the parent shape. NOTE: The currently selected stroke is destroyed.
 
void setKeepAspectRatio (bool keepAspect)
 
void setMinimumHeight (qreal height)
 
void setName (const QString &name)
 
virtual void setPaintOrder (PaintOrder first, PaintOrder second)
 setPaintOrder set the paint order. As there's only three entries in any given paintorder, you only need to have the first and second entry to set it.
 
void setParent (KoShapeContainer *parent)
 
virtual void setPosition (const QPointF &position)
 Set the position of the shape in pt.
 
void setPrintable (bool on)
 
virtual void setResolution (qreal xRes, qreal yRes)
 
void setSelectable (bool selectable)
 
void setShapeId (const QString &id)
 
virtual void setSize (const QSizeF &size)
 Resize the shape.
 
virtual void setStroke (KoShapeStrokeModelSP stroke)
 
void setToolDelegates (const QSet< KoShape * > &delegates)
 
void setTransformation (const QTransform &matrix)
 
void setTransparency (qreal transparency)
 
void setUserData (KoShapeUserData *userData)
 
void setVisible (bool on)
 
void setZIndex (qint16 zIndex)
 
QString shapeId () const
 
QPointF shapeToDocument (const QPointF &point) const
 Transforms point from shape coordinates to document coordinates.
 
QRectF shapeToDocument (const QRectF &rect) const
 Transforms rect from shape coordinates to document coordinates.
 
void shear (qreal sx, qreal sy)
 Shear the shape The shape will be sheared using the zero-point which is the top-left corner.
 
virtual QSizeF size () const
 Get the size of the shape in pt.
 
virtual KoSnapData snapData () const
 Returns additional snap data the shape wants to have snapping to.
 
virtual KoShapeStrokeModelSP stroke () const
 
KoInsets strokeInsets () const
 
QSet< KoShape * > toolDelegates () const
 
QTransform transformation () const
 Returns the shapes local transformation matrix.
 
qreal transparency (bool recursive=false) const
 
virtual void update () const
 
virtual void updateAbsolute (const QRectF &rect) const
 
KoShapeUserData * userData () const
 
virtual void waitUntilReady (bool asynchronous=true) const
 
qint16 zIndex () const
 
virtual ~KoShape ()
 Destructor.
 

Static Public Member Functions

static KisReferenceImage * fromClipboard (const KisCoordinatesConverter &converter)
 
static KisReferenceImage * fromFile (const QString &filename, const KisCoordinatesConverter &converter, QWidget *parent)
 
static KisReferenceImage * fromPaintDevice (KisPaintDeviceSP src, const KisCoordinatesConverter &converter, QWidget *parent)
 
static KisReferenceImage * fromQImage (const KisCoordinatesConverter &converter, const QImage &img)
 
static KisReferenceImage * fromXml (const QDomElement &elem)
 
- Static Public Member Functions inherited from KoShape
static QRectF absoluteOutlineRect (const QList< KoShape * > &shapes)
 
static QRectF boundingRect (const QList< KoShape * > &shapes)
 
static bool compareShapeZIndex (KoShape *s1, KoShape *s2)
 
static KisHandlePainterHelper createHandlePainterHelperDocument (QPainter *painter, KoShape *shape, qreal handleRadius, int decorationThickness)
 
static KisHandlePainterHelper createHandlePainterHelperView (QPainter *painter, KoShape *shape, const KoViewConverter &converter, qreal handleRadius=0.0, int decorationThickness=1)
 
static QVector< PaintOrder > defaultPaintOrder ()
 default paint order as per SVG specification
 
static QList< KoShape * > linearizeSubtree (const QList< KoShape * > &shapes)
 
static QList< KoShape * > linearizeSubtreeSorted (const QList< KoShape * > &shapes)
 

Private Attributes

QSharedDataPointer< Private > d
 

Additional Inherited Members

- Public Types inherited from KoShape
enum  ChangeType {
  PositionChanged , RotationChanged , ScaleChanged , ShearChanged ,
  SizeChanged , GenericMatrixChange , KeepAspectRatioChange , ParentChanged ,
  Deleted , StrokeChanged , BackgroundChanged , BorderChanged ,
  ParameterChanged , ContentChanged , TextContourMarginChanged , ChildChanged ,
  ConnectionPointChanged , ClipPathChanged , ClipMaskChanged , TransparencyChanged ,
  GeometryProtectedChanged
}
 Used by shapeChanged() to select which change was made. More...
 
enum  ChildZOrderPolicy { ChildZDefault , ChildZParentChild = ChildZDefault , ChildZPassThrough }
 Used by compareShapeZIndex() to order shapes. More...
 
enum  PaintOrder { Fill , Stroke , Markers }
 
- Static Public Attributes inherited from KoShape
static const qint16 maxZIndex = std::numeric_limits<qint16>::max()
 
static const qint16 minZIndex = std::numeric_limits<qint16>::min()
 
- Protected Member Functions inherited from KoShape
 KoShape (const KoShape &rhs)
 
QList< ShapeChangeListener * > listeners () const
 
void setSizeImpl (const QSizeF &size) const
 
virtual void shapeChanged (ChangeType type, KoShape *shape=0)
 
void shapeChangedPriv (KoShape::ChangeType type)
 
QTransform transform () const
 return the current matrix that contains the rotation/scale/position of this shape
 

Detailed Description

The KisReferenceImage class represents a single reference image.

Definition at line 29 of file KisReferenceImage.h.

Constructor & Destructor Documentation

◆ KisReferenceImage() [1/2]

KisReferenceImage::KisReferenceImage ( )

Definition at line 169 of file KisReferenceImage.cpp.

170 : d(new Private())
171{
172 setKeepAspectRatio(true);
173}
QSharedDataPointer< Private > d
void setKeepAspectRatio(bool keepAspect)
Definition KoShape.cpp:865

References KoShape::setKeepAspectRatio().

◆ KisReferenceImage() [2/2]

KisReferenceImage::KisReferenceImage ( const KisReferenceImage & rhs)

Definition at line 175 of file KisReferenceImage.cpp.

176 : KoShape(rhs)
177 , d(rhs.d)
178{}
KoShape()
Constructor.
Definition KoShape.cpp:136

◆ ~KisReferenceImage()

KisReferenceImage::~KisReferenceImage ( )

Definition at line 180 of file KisReferenceImage.cpp.

181{}

Member Function Documentation

◆ cloneShape()

KoShape * KisReferenceImage::cloneShape ( ) const
overridevirtual

creates a deep copy of the shape or shape's subtree

Returns
a cloned shape

Reimplemented from KoShape.

Definition at line 512 of file KisReferenceImage.cpp.

513{
514 return new KisReferenceImage(*this);
515}

References KisReferenceImage().

◆ documentToPixel()

QPointF KisReferenceImage::documentToPixel ( const QPointF & docPoint)

Definition at line 355 of file KisReferenceImage.cpp.

356{
357 QSizeF shapeSize = size();
358 QTransform scale = QTransform::fromScale(d->image.width() / shapeSize.width(), d->image.height() / shapeSize.height());
359
360 QTransform transform = absoluteTransformation().inverted() * scale;
361 QPointF localPosition = docPoint * transform;
362
363 return localPosition;
364}
virtual QSizeF size() const
Get the size of the shape in pt.
Definition KoShape.cpp:735
QTransform absoluteTransformation() const
Definition KoShape.cpp:330
void scale(qreal sx, qreal sy)
Scale the shape using the zero-point which is the top-left corner.
Definition KoShape.cpp:210
QTransform transform() const
return the current matrix that contains the rotation/scale/position of this shape
Definition KoShape.cpp:948

References KoShape::absoluteTransformation(), d, KoShape::scale(), KoShape::size(), and KoShape::transform().

◆ documentToPixelFloored()

QPoint KisReferenceImage::documentToPixelFloored ( const QPointF & docPoint)

Definition at line 367 of file KisReferenceImage.cpp.

368{
369 QPointF localPoint = documentToPixel(docPoint);
370 return QPoint(qFloor(localPoint.x()), qFloor(localPoint.y()));
371}
QPointF documentToPixel(const QPointF &docPoint)

References documentToPixel().

◆ embed()

bool KisReferenceImage::embed ( )

Definition at line 329 of file KisReferenceImage.cpp.

330{
331 return d->embed;
332}

References d.

◆ filename()

QString KisReferenceImage::filename ( ) const

Definition at line 339 of file KisReferenceImage.cpp.

340{
341 return d->externalFilename;
342}

References d.

◆ fromClipboard()

KisReferenceImage * KisReferenceImage::fromClipboard ( const KisCoordinatesConverter & converter)
static

Definition at line 206 of file KisReferenceImage.cpp.

207{
208 KisImageSP clipImage = KisClipboard::instance()->clipImage(true);
209 return fromPaintDevice(clipImage->projection(), converter, nullptr);
210}
static KisClipboard * instance()
KisImageSP clipImage(bool showPopup, int overridePasteBehaviour=-1) const
KisPaintDeviceSP projection() const
static KisReferenceImage * fromPaintDevice(KisPaintDeviceSP src, const KisCoordinatesConverter &converter, QWidget *parent)

References KisClipboard::clipImage(), fromPaintDevice(), KisClipboard::instance(), and KisImage::projection().

◆ fromFile()

KisReferenceImage * KisReferenceImage::fromFile ( const QString & filename,
const KisCoordinatesConverter & converter,
QWidget * parent )
static

Load a reference image from specified file. If parent is provided and the image cannot be loaded, a warning message will be displayed to user.

Returns
reference image or null if one could not be loaded

Definition at line 183 of file KisReferenceImage.cpp.

184{
185 KisReferenceImage *reference = new KisReferenceImage();
186 reference->d->externalFilename = filename;
187 bool ok = reference->d->loadFromFile();
188
189 if (ok) {
190 QRect r = QRect(QPoint(), reference->d->image.size());
191 QSizeF shapeSize = converter.imageToDocument(r).size();
192 reference->setSize(shapeSize);
193 } else {
194 delete reference;
195
196 if (parent) {
197 QMessageBox::critical(parent, i18nc("@title:window", "Krita"), i18n("Could not load %1.", filename));
198 }
199
200 return nullptr;
201 }
202
203 return reference;
204}
_Private::Traits< T >::Result imageToDocument(const T &obj) const
The KisReferenceImage class represents a single reference image.
QString filename() const
KoShapeContainer * parent() const
Definition KoShape.cpp:860
virtual void setSize(const QSizeF &size)
Resize the shape.
Definition KoShape.cpp:249

References d, filename(), KisCoordinatesConverter::imageToDocument(), KisReferenceImage(), KoShape::parent(), and KoShape::setSize().

◆ fromPaintDevice()

KisReferenceImage * KisReferenceImage::fromPaintDevice ( KisPaintDeviceSP src,
const KisCoordinatesConverter & converter,
QWidget * parent )
static

Load a reference image from specified paint device.

Returns
reference image or null if one could not be loaded

Definition at line 213 of file KisReferenceImage.cpp.

214{
215 if (!src) {
216 return nullptr;
217 }
218
219 auto *reference = new KisReferenceImage();
220#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
221 if (src->colorSpace()->colorModelId() == RGBAColorModelID) {
222 reference->d->image = src->convertToQImage(src->colorSpace()->profile());
223 reference->d->image.setColorSpace(KoColorSpaceRegistry::instance()->QColorSpaceForProfile(src->colorSpace()->profile()));
224 } else {
225 reference->d->image = src->convertToQImage(KoColorSpaceRegistry::instance()->p709SRGBProfile());
226 }
227#else
228 reference->d->image = src->convertToQImage(KoColorSpaceRegistry::instance()->p709SRGBProfile());
229#endif
230
231 QRect r = QRect(QPoint(), reference->d->image.size());
232 QSizeF size = converter.imageToDocument(r).size();
233 reference->setSize(size);
234
235 return reference;
236}
const KoID RGBAColorModelID("RGBA", ki18n("RGB/Alpha"))
static KoColorSpaceRegistry * instance()

References KisCoordinatesConverter::imageToDocument(), KoColorSpaceRegistry::instance(), KisReferenceImage(), RGBAColorModelID, and KoShape::size().

◆ fromQImage()

KisReferenceImage * KisReferenceImage::fromQImage ( const KisCoordinatesConverter & converter,
const QImage & img )
static

Definition at line 238 of file KisReferenceImage.cpp.

239{
240 KisReferenceImage *reference = new KisReferenceImage();
241 bool ok = reference->d->loadFromQImage(img);
242
243 if (ok) {
244 QRect r = QRect(QPoint(), reference->d->image.size());
245 QSizeF size = converter.imageToDocument(r).size();
246 reference->setSize(size);
247 } else {
248 delete reference;
249 reference = 0;
250 }
251
252 return reference;
253}

References d, KisCoordinatesConverter::imageToDocument(), KisReferenceImage(), KoShape::setSize(), and KoShape::size().

◆ fromXml()

KisReferenceImage * KisReferenceImage::fromXml ( const QDomElement & elem)
static

Definition at line 429 of file KisReferenceImage.cpp.

430{
431 auto *reference = new KisReferenceImage();
432
433 const QString &src = elem.attribute("src");
434
435 if (src.startsWith("file://")) {
436 reference->d->externalFilename = src.mid(7);
437 reference->d->embed = false;
438 } else {
439 reference->d->internalFilename = src;
440 reference->d->embed = true;
441 }
442
443 qreal width = KisDomUtils::toDouble(elem.attribute("width", "100"));
444 qreal height = KisDomUtils::toDouble(elem.attribute("height", "100"));
445 reference->setSize(QSizeF(width, height));
446 reference->setKeepAspectRatio(elem.attribute("keepAspectRatio", "true").toLower() == "true");
447
448 auto transform = SvgTransformParser(elem.attribute("transform")).transform();
449 reference->setTransformation(transform);
450
451 qreal opacity = KisDomUtils::toDouble(elem.attribute("opacity", "1"));
452 reference->setTransparency(1.0 - opacity);
453
454 qreal saturation = KisDomUtils::toDouble(elem.attribute("saturation", "1"));
455 reference->setSaturation(saturation);
456
457 return reference;
458}
QTransform transform() const
double toDouble(const QString &str, bool *ok=nullptr)

References KisReferenceImage(), saturation(), KisDomUtils::toDouble(), KoShape::transform(), and SvgTransformParser::transform().

◆ getCachedImage()

QImage KisReferenceImage::getCachedImage ( )

Definition at line 505 of file KisReferenceImage.cpp.

506{
507 if (d->cachedImage.isNull()) d->updateCache();
508
509 return d->cachedImage;
510}

References d.

◆ getImage()

QImage KisReferenceImage::getImage ( )

Definition at line 500 of file KisReferenceImage.cpp.

501{
502 return d->image;
503}

References d.

◆ getPixel()

KoColor KisReferenceImage::getPixel ( QPointF position)

Definition at line 373 of file KisReferenceImage.cpp.

374{
375 KoColor transparent;
376 transparent.setOpacity(0.0);
377 if (transparency() == 1.0) return transparent;
378
379 const QPoint localPosition = documentToPixelFloored(position);
380
381 if (d->cachedImage.isNull()) {
382 d->updateCache();
383 }
384
385#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
386 const KoColorProfile *profile = KoColorSpaceRegistry::instance()->profileForQColorSpace(d->image.colorSpace());
388#else
390#endif
391
392 KoColor c(cs);
393 QColor pixel = d->cachedImage.pixelColor(localPosition);
394 QVector<float> channels = {
395 static_cast<float>(pixel.blueF()),
396 static_cast<float>(pixel.greenF()),
397 static_cast<float>(pixel.redF()),
398 1.0f};
399 cs->fromNormalisedChannelsValue( c.data(),channels);
400
401 return c;
402}
const KoID Integer16BitsColorDepthID("U16", ki18n("16-bit integer/channel"))
QPoint documentToPixelFloored(const QPointF &docPoint)
virtual void fromNormalisedChannelsValue(quint8 *pixel, const QVector< float > &values) const =0
void setOpacity(quint8 alpha)
Definition KoColor.cpp:333
QString id() const
Definition KoID.cpp:63
qreal transparency(bool recursive=false) const
Definition KoShape.cpp:645
QPointF position() const
Get the position of the shape in pt.
Definition KoShape.cpp:740
const KoColorSpace * colorSpace(const QString &colorModelId, const QString &colorDepthId, const KoColorProfile *profile)
const KoColorSpace * rgb8(const QString &profileName=QString())
const KoColorProfile * profileForQColorSpace(const QColorSpace &space)
profileForQColorSpace Find a KoColorProfile that matches a given QColorSpace. This will use the QColo...

References KoColorSpaceRegistry::colorSpace(), d, KoColor::data(), documentToPixelFloored(), KoColorSpace::fromNormalisedChannelsValue(), KoID::id(), KoColorSpaceRegistry::instance(), Integer16BitsColorDepthID, KoShape::position(), KoColorSpaceRegistry::profileForQColorSpace(), KoColorSpaceRegistry::rgb8(), RGBAColorModelID, KoColor::setOpacity(), and KoShape::transparency().

◆ hasLocalFile()

bool KisReferenceImage::hasLocalFile ( )

Definition at line 334 of file KisReferenceImage.cpp.

335{
336 return !d->externalFilename.isEmpty();
337}

References d.

◆ internalFile()

QString KisReferenceImage::internalFile ( ) const

Definition at line 344 of file KisReferenceImage.cpp.

345{
346 return d->internalFilename;
347}

References d.

◆ loadImage()

bool KisReferenceImage::loadImage ( KoStore * store)

Definition at line 478 of file KisReferenceImage.cpp.

479{
480 if (!d->embed) {
481 return d->loadFromFile();
482 }
483
484 if (!store->open(d->internalFilename)) {
485 return false;
486 }
487
488 KoStoreDevice storeDev(store);
489 if (!storeDev.open(QIODevice::ReadOnly)) {
490 return false;
491 }
492
493 if (!d->image.load(&storeDev, "PNG")) {
494 return false;
495 }
496
497 return store->close();
498}
bool close()
Definition KoStore.cpp:156
bool open(const QString &name)
Definition KoStore.cpp:109

References KoStore::close(), d, KoStore::open(), and KoStoreDevice::open().

◆ paint()

void KisReferenceImage::paint ( QPainter & painter) const
overridevirtual

Paint the shape fill The class extending this one is responsible for painting itself. painter is expected to be preconfigured to work in "document" pixels.

Parameters
painterused for painting the shape

Implements KoShape.

Definition at line 255 of file KisReferenceImage.cpp.

256{
257 if (!parent()) return;
258
259 gc.save();
260
261 QSizeF shapeSize = size();
262 // scale and rotation done by the user (excluding zoom)
263 QTransform transform = QTransform::fromScale(shapeSize.width() / d->image.width(), shapeSize.height() / d->image.height());
264
265 if (d->cachedImage.isNull()) {
266 // detach the data
267 const_cast<KisReferenceImage*>(this)->d->updateCache();
268 }
269
270 qreal scale;
271 // scale from the highDPI display
272 QTransform devicePixelRatioFTransform = QTransform::fromScale(gc.device()->devicePixelRatioF(), gc.device()->devicePixelRatioF());
273 // all three transformations: scale and rotation done by the user, scale from highDPI display, and zoom + rotation of the view
274 // order: zoom/rotation of the view; scale to high res; scale and rotation done by the user
275 QImage prescaled = d->mipmap.getClosestWithoutWorkaroundBorder(transform * devicePixelRatioFTransform * gc.transform(), &scale);
276 transform.scale(1.0 / scale, 1.0 / scale);
277
278 // Color conversion.
279 QImage *targetD = dynamic_cast<QImage*>(gc.device());
280#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
281 const bool getTargetCs = (targetD && targetD->colorSpace().colorModel() == QColorSpace::ColorModel::Rgb);
282
284 const KoColorProfile *sourceP = KoColorSpaceRegistry::instance()->profileForQColorSpace(d->image.colorSpace());
285 if (targetP != sourceP) {
287 dev->convertFromQImage(prescaled, sourceP);
289 prescaled = dev->convertToQImage(targetP);
290 if (getTargetCs) {
291 prescaled.setColorSpace(targetD->colorSpace());
292 } else {
293 prescaled.setColorSpace(QColorSpace(QColorSpace::SRgb));
294 }
295 }
296#endif
297
298 if (scale > 1.0) {
299 // enlarging should be done without smooth transformation
300 // so the user can see pixels just as they are painted
301 gc.setRenderHints(QPainter::Antialiasing);
302 } else {
303 gc.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
304 }
305 gc.setClipRect(QRectF(QPointF(), shapeSize), Qt::IntersectClip);
306 gc.setTransform(transform, true);
307 gc.drawImage(QPoint(), prescaled);
308
309 gc.restore();
310}
const KoID Integer8BitsColorDepthID("U8", ki18n("8-bit integer/channel"))
QImage convertToQImage(const KoColorProfile *dstProfile, qint32 x, qint32 y, qint32 w, qint32 h, KoColorConversionTransformation::Intent renderingIntent=KoColorConversionTransformation::internalRenderingIntent(), KoColorConversionTransformation::ConversionFlags conversionFlags=KoColorConversionTransformation::internalConversionFlags()) const
void convertFromQImage(const QImage &image, const KoColorProfile *profile, qint32 offsetX=0, qint32 offsetY=0)
void convertTo(const KoColorSpace *dstColorSpace, KoColorConversionTransformation::Intent renderingIntent=KoColorConversionTransformation::internalRenderingIntent(), KoColorConversionTransformation::ConversionFlags conversionFlags=KoColorConversionTransformation::internalConversionFlags(), KUndo2Command *parentCommand=nullptr, KoUpdater *progressUpdater=nullptr)
const KoColorProfile * p709SRGBProfile() const

References KisPaintDevice::convertFromQImage(), KisPaintDevice::convertTo(), KisPaintDevice::convertToQImage(), d, KoID::id(), KoColorSpaceRegistry::instance(), Integer8BitsColorDepthID, KoColorSpaceRegistry::p709SRGBProfile(), KoShape::parent(), KoColorSpaceRegistry::profileForQColorSpace(), RGBAColorModelID, KoShape::scale(), KoShape::size(), and KoShape::transform().

◆ saturation()

qreal KisReferenceImage::saturation ( ) const

Definition at line 318 of file KisReferenceImage.cpp.

319{
320 return d->saturation;
321}

References d.

◆ saveImage()

bool KisReferenceImage::saveImage ( KoStore * store) const

Definition at line 460 of file KisReferenceImage.cpp.

461{
462 if (!d->embed) return true;
463
464 if (!store->open(d->internalFilename)) {
465 return false;
466 }
467
468 bool saved = false;
469
470 KoStoreDevice storeDev(store);
471 if (storeDev.open(QIODevice::WriteOnly)) {
472 saved = d->image.save(&storeDev, "PNG");
473 }
474
475 return store->close() && saved;
476}

References KoStore::close(), d, KoStore::open(), and KoStoreDevice::open().

◆ saveXml()

void KisReferenceImage::saveXml ( QDomDocument & document,
QDomElement & parentElement,
int id )

Definition at line 404 of file KisReferenceImage.cpp.

405{
406 d->id = id;
407
408 QDomElement element = document.createElement("referenceimage");
409
410 if (d->embed) {
411 d->internalFilename = QString("reference_images/%1.png").arg(id);
412 }
413
414 const QString src = d->embed ? d->internalFilename : (QString("file://") + d->externalFilename);
415 element.setAttribute("src", src);
416
417 const QSizeF &shapeSize = size();
418 element.setAttribute("width", KisDomUtils::toString(shapeSize.width()));
419 element.setAttribute("height", KisDomUtils::toString(shapeSize.height()));
420 element.setAttribute("keepAspectRatio", keepAspectRatio() ? "true" : "false");
421 element.setAttribute("transform", SvgUtil::transformToString(transform()));
422
423 element.setAttribute("opacity", KisDomUtils::toString(1.0 - transparency()));
424 element.setAttribute("saturation", KisDomUtils::toString(d->saturation));
425
426 parentElement.appendChild(element);
427}
bool keepAspectRatio() const
Definition KoShape.cpp:873
static QString transformToString(const QTransform &transform)
Converts specified transformation to a string.
Definition SvgUtil.cpp:104
QString toString(const QString &value)

References d, KoShape::keepAspectRatio(), KoShape::size(), KisDomUtils::toString(), KoShape::transform(), SvgUtil::transformToString(), and KoShape::transparency().

◆ setEmbed()

void KisReferenceImage::setEmbed ( bool embed)

Definition at line 323 of file KisReferenceImage.cpp.

324{
325 KIS_SAFE_ASSERT_RECOVER_RETURN(embed || !d->externalFilename.isEmpty());
326 d->embed = embed;
327}
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128

References d, embed(), and KIS_SAFE_ASSERT_RECOVER_RETURN.

◆ setFilename()

void KisReferenceImage::setFilename ( const QString & filename)

Definition at line 350 of file KisReferenceImage.cpp.

351{
352 d->externalFilename = filename;
353}

References d, and filename().

◆ setSaturation()

void KisReferenceImage::setSaturation ( qreal saturation)

Definition at line 312 of file KisReferenceImage.cpp.

313{
314 d->saturation = saturation;
315 d->cachedImage = QImage();
316}

References d, and saturation().

Member Data Documentation

◆ d

QSharedDataPointer<Private> KisReferenceImage::d
private

Definition at line 93 of file KisReferenceImage.h.


The documentation for this class was generated from the following files: