14#include <QApplication>
18#include <QImageReader>
60 reader.setDecideFormatFromContent(
true);
61 image = reader.read();
64 reader.setAutoDetectImageFormat(
true);
65 image = reader.read();
95#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
96 if (
image.colorSpace().colorModel() != QColorSpace::ColorModel::Rgb || !
image.colorSpace().isValid()) {
97 image.convertToColorSpace(QColorSpace(QColorSpace::SRgb));
100 image.convertToColorSpace(QColorSpace(QColorSpace::SRgb));
103 return (!
image.isNull());
108 return !
image.isNull();
118 gc2.drawImage(QPoint(),
image);
131 , newSaturation(newSaturation)
133 images.reserve(shapes.count());
135 Q_FOREACH(
auto *shape, shapes) {
141 Q_FOREACH(
auto *image,
images) {
148 auto saturationIterator = oldSaturations.begin();
149 Q_FOREACH(
auto *image, images) {
150 image->setSaturation(*saturationIterator);
152 saturationIterator++;
158 Q_FOREACH(
auto *image, images) {
159 image->setSaturation(newSaturation);
181 reference->
d->externalFilename =
filename;
182 bool ok = reference->
d->loadFromFile();
185 QRect r = QRect(QPoint(), reference->
d->image.size());
192 QMessageBox::critical(
parent, i18nc(
"@title:window",
"Krita"), i18n(
"Could not load %1.",
filename));
216#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
218 reference->d->image = src->convertToQImage(src->colorSpace()->profile());
227 QRect r = QRect(QPoint(), reference->d->image.size());
229 reference->setSize(
size);
237 bool ok = reference->
d->loadFromQImage(img);
240 QRect r = QRect(QPoint(), reference->
d->image.size());
257 QSizeF shapeSize =
size();
259 QTransform
transform = QTransform::fromScale(shapeSize.width() /
d->image.width(), shapeSize.height() /
d->image.height());
261 if (
d->cachedImage.isNull()) {
268 QTransform devicePixelRatioFTransform = QTransform::fromScale(gc.device()->devicePixelRatioF(), gc.device()->devicePixelRatioF());
271 QImage prescaled =
d->mipmap.getClosestWithoutWorkaroundBorder(
transform * devicePixelRatioFTransform * gc.transform(), &
scale);
275 QImage *targetD =
dynamic_cast<QImage*
>(gc.device());
276#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
277 const bool getTargetCs = (targetD && targetD->colorSpace().colorModel() == QColorSpace::ColorModel::Rgb);
281 if (targetP != sourceP) {
287 prescaled.setColorSpace(targetD->colorSpace());
289 prescaled.setColorSpace(QColorSpace(QColorSpace::SRgb));
297 gc.setRenderHints(QPainter::Antialiasing);
299 gc.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
301 gc.setClipRect(QRectF(QPointF(), shapeSize), Qt::IntersectClip);
303 gc.drawImage(QPoint(), prescaled);
311 d->cachedImage = QImage();
316 return d->saturation;
332 return !
d->externalFilename.isEmpty();
337 return d->externalFilename;
342 return d->internalFilename;
357 const QSizeF shapeSize =
size();
358 const QTransform
scale = QTransform::fromScale(
d->image.width() / shapeSize.width(),
d->image.height() / shapeSize.height());
363 if (
d->cachedImage.isNull()) {
367#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
375 QColor pixel =
d->cachedImage.pixelColor(localPosition.toPoint());
377 static_cast<float>(pixel.blueF()),
378 static_cast<float>(pixel.greenF()),
379 static_cast<float>(pixel.redF()),
390 QDomElement element = document.createElement(
"referenceimage");
393 d->internalFilename = QString(
"reference_images/%1.png").arg(
id);
396 const QString src =
d->embed ?
d->internalFilename : (QString(
"file://") +
d->externalFilename);
397 element.setAttribute(
"src", src);
399 const QSizeF &shapeSize =
size();
402 element.setAttribute(
"keepAspectRatio",
keepAspectRatio() ?
"true" :
"false");
408 parentElement.appendChild(element);
415 const QString &src = elem.attribute(
"src");
417 if (src.startsWith(
"file://")) {
418 reference->d->externalFilename = src.mid(7);
419 reference->d->embed =
false;
421 reference->d->internalFilename = src;
422 reference->d->embed =
true;
427 reference->setSize(QSizeF(width, height));
428 reference->setKeepAspectRatio(elem.attribute(
"keepAspectRatio",
"true").toLower() ==
"true");
434 reference->setTransparency(1.0 - opacity);
444 if (!
d->embed)
return true;
446 if (!store->
open(
d->internalFilename)) {
453 if (storeDev.
open(QIODevice::WriteOnly)) {
454 saved =
d->image.save(&storeDev,
"PNG");
457 return store->
close() && saved;
463 return d->loadFromFile();
466 if (!store->
open(
d->internalFilename)) {
471 if (!storeDev.
open(QIODevice::ReadOnly)) {
475 if (!
d->image.load(&storeDev,
"PNG")) {
479 return store->
close();
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)
static KisReferenceImage * fromClipboard(const KisCoordinatesConverter &converter)
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