15#include <QApplication>
19#include <QImageReader>
61 reader.setDecideFormatFromContent(
true);
62 image = reader.read();
65 reader.setAutoDetectImageFormat(
true);
66 image = reader.read();
96#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
97 if (
image.colorSpace().colorModel() != QColorSpace::ColorModel::Rgb || !
image.colorSpace().isValid()) {
98 image.convertToColorSpace(QColorSpace(QColorSpace::SRgb));
101 image.convertToColorSpace(QColorSpace(QColorSpace::SRgb));
104 return (!
image.isNull());
110 return !
image.isNull();
120 gc2.drawImage(QPoint(),
image);
136 , newSaturation(newSaturation)
138 images.reserve(shapes.count());
140 Q_FOREACH(
auto *shape, shapes) {
146 Q_FOREACH(
auto *image,
images) {
153 auto saturationIterator = oldSaturations.begin();
154 Q_FOREACH(
auto *image, images) {
155 image->setSaturation(*saturationIterator);
157 saturationIterator++;
163 Q_FOREACH(
auto *image, images) {
164 image->setSaturation(newSaturation);
186 reference->
d->externalFilename =
filename;
187 bool ok = reference->
d->loadFromFile();
190 QRect r = QRect(QPoint(), reference->
d->image.size());
197 QMessageBox::critical(
parent, i18nc(
"@title:window",
"Krita"), i18n(
"Could not load %1.",
filename));
221#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
223 reference->d->image = src->convertToQImage(src->colorSpace()->profile());
232 QRect r = QRect(QPoint(), reference->d->image.size());
234 reference->setSize(
size);
242 bool ok = reference->
d->loadFromQImage(img);
245 QRect r = QRect(QPoint(), reference->
d->image.size());
262 QSizeF shapeSize =
size();
264 QTransform
transform = QTransform::fromScale(shapeSize.width() /
d->image.width(), shapeSize.height() /
d->image.height());
266 if (
d->cachedImage.isNull()) {
273 QTransform devicePixelRatioFTransform = QTransform::fromScale(gc.device()->devicePixelRatioF(), gc.device()->devicePixelRatioF());
276 QImage prescaled =
d->mipmap.getClosestWithoutWorkaroundBorder(
transform * devicePixelRatioFTransform * gc.transform(), &
scale);
280 QImage *targetD =
dynamic_cast<QImage*
>(gc.device());
281#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
282 const bool getTargetCs = (targetD && targetD->colorSpace().colorModel() == QColorSpace::ColorModel::Rgb);
286 if (targetP != sourceP) {
292 prescaled.setColorSpace(targetD->colorSpace());
294 prescaled.setColorSpace(QColorSpace(QColorSpace::SRgb));
302 gc.setRenderHints(QPainter::Antialiasing);
304 gc.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
306 gc.setClipRect(QRectF(QPointF(), shapeSize), Qt::IntersectClip);
308 gc.drawImage(QPoint(), prescaled);
316 d->cachedImage = QImage();
321 return d->saturation;
337 return !
d->externalFilename.isEmpty();
342 return d->externalFilename;
347 return d->internalFilename;
358 QSizeF shapeSize =
size();
359 QTransform
scale = QTransform::fromScale(
d->image.width() / shapeSize.width(),
d->image.height() / shapeSize.height());
362 QPointF localPosition = docPoint *
transform;
364 return localPosition;
371 return QPoint(qFloor(localPoint.x()), qFloor(localPoint.y()));
382 if (
d->cachedImage.isNull()) {
386#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
394 QColor pixel =
d->cachedImage.pixelColor(localPosition);
396 static_cast<float>(pixel.blueF()),
397 static_cast<float>(pixel.greenF()),
398 static_cast<float>(pixel.redF()),
409 QDomElement element = document.createElement(
"referenceimage");
412 d->internalFilename = QString(
"reference_images/%1.png").arg(
id);
415 const QString src =
d->embed ?
d->internalFilename : (QString(
"file://") +
d->externalFilename);
416 element.setAttribute(
"src", src);
418 const QSizeF &shapeSize =
size();
421 element.setAttribute(
"keepAspectRatio",
keepAspectRatio() ?
"true" :
"false");
427 parentElement.appendChild(element);
434 const QString &src = elem.attribute(
"src");
436 if (src.startsWith(
"file://")) {
437 reference->d->externalFilename = src.mid(7);
438 reference->d->embed =
false;
440 reference->d->internalFilename = src;
441 reference->d->embed =
true;
446 reference->setSize(QSizeF(width, height));
447 reference->setKeepAspectRatio(elem.attribute(
"keepAspectRatio",
"true").toLower() ==
"true");
453 reference->setTransparency(1.0 - opacity);
463 if (!
d->embed)
return true;
465 if (!store->
open(
d->internalFilename)) {
472 if (storeDev.
open(QIODevice::WriteOnly)) {
473 saved =
d->image.save(&storeDev,
"PNG");
476 return store->
close() && saved;
482 return d->loadFromFile();
485 if (!store->
open(
d->internalFilename)) {
490 if (!storeDev.
open(QIODevice::ReadOnly)) {
494 if (!
d->image.load(&storeDev,
"PNG")) {
498 return store->
close();
508 if (
d->cachedImage.isNull())
d->updateCache();
510 return d->cachedImage;
const KoID Float32BitsColorDepthID("F32", ki18n("32-bit float/channel"))
const KoID Float16BitsColorDepthID("F16", ki18n("16-bit float/channel"))
const KoID Integer8BitsColorDepthID("U8", ki18n("8-bit integer/channel"))
const KoID Integer16BitsColorDepthID("U16", ki18n("16-bit integer/channel"))
const KoID RGBAColorModelID("RGBA", ki18n("RGB/Alpha"))
static KisClipboard * instance()
_Private::Traits< T >::Result imageToDocument(const T &obj) const
bool openPath(const QString &path, OpenFlags flags=None)
openPath Open a Path
QImage convertToQImage(qint32 x1, qint32 y1, qint32 width, qint32 height, const KoColorProfile *profile)
const KoColorSpace * colorSpace() const
void convertImageColorSpace(const KoColorSpace *dstColorSpace, KoColorConversionTransformation::Intent renderingIntent, KoColorConversionTransformation::ConversionFlags conversionFlags)
QRect bounds() const override
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)
static KisPart * instance()
void removeDocument(KisDocument *document, bool deleteDocument=true)
KisDocument * createTemporaryDocument() const
The KisReferenceImage class represents a single reference image.
bool saveImage(KoStore *store) const
bool loadImage(KoStore *store)
void paint(QPainter &gc) const override
Paint the shape fill The class extending this one is responsible for painting itself....
static KisReferenceImage * fromFile(const QString &filename, const KisCoordinatesConverter &converter, QWidget *parent)
KoShape * cloneShape() const override
creates a deep copy of the shape or shape's subtree
void setFilename(const QString &filename)
QPointF documentToPixel(const QPointF &docPoint)
static KisReferenceImage * fromClipboard(const KisCoordinatesConverter &converter)
QPoint documentToPixelFloored(const QPointF &docPoint)
void setEmbed(bool embed)
KoColor getPixel(QPointF position)
static KisReferenceImage * fromQImage(const KisCoordinatesConverter &converter, const QImage &img)
void setSaturation(qreal saturation)
void saveXml(QDomDocument &document, QDomElement &parentElement, int id)
QString internalFile() const
static KisReferenceImage * fromPaintDevice(KisPaintDeviceSP src, const KisCoordinatesConverter &converter, QWidget *parent)
QSharedDataPointer< Private > d
static KisReferenceImage * fromXml(const QDomElement &elem)
virtual KoID colorModelId() const =0
virtual KoID colorDepthId() const =0
virtual void fromNormalisedChannelsValue(quint8 *pixel, const QVector< float > &values) const =0
virtual const KoColorProfile * profile() const =0
void setOpacity(quint8 alpha)
virtual QSizeF size() const
Get the size of the shape in pt.
void setKeepAspectRatio(bool keepAspect)
KoShapeContainer * parent() const
QTransform absoluteTransformation() const
void scale(qreal sx, qreal sy)
Scale the shape using the zero-point which is the top-left corner.
bool keepAspectRatio() const
QTransform transform() const
return the current matrix that contains the rotation/scale/position of this shape
qreal transparency(bool recursive=false) const
virtual void setSize(const QSizeF &size)
Resize the shape.
QPointF position() const
Get the position of the shape in pt.
bool open(OpenMode m) override
bool open(const QString &name)
static QString transformToString(const QTransform &transform)
Converts specified transformation to a string.
#define KIS_SAFE_ASSERT_RECOVER_BREAK(cond)
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
KUndo2MagicString kundo2_i18n(const char *text)
double toDouble(const QString &str, bool *ok=nullptr)
QString toString(const QString &value)
QImage convertQImageToGrayA(const QImage &image)
bool loadFromQImage(const QImage &img)
SetSaturationCommand(const QList< KoShape * > &images, qreal newSaturation, KUndo2Command *parent=0)
QVector< KisReferenceImage * > images
QVector< qreal > oldSaturations
const KoColorSpace * colorSpace(const QString &colorModelId, const QString &colorDepthId, const KoColorProfile *profile)
static KoColorSpaceRegistry * instance()
const KoColorProfile * p709SRGBProfile() const
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...
const KoColorProfile * p2020PQProfile() const