Commit b9aa57cd authored by Boudewijn Rempt's avatar Boudewijn Rempt

* When setting a profile in an image, do a conversion.

* Do not keep a copy of the profile in the image; it's already in the colorspace
* Make the image properties dialog not depend on KisView
* add another getter to the colorspace registry, one that takes a profile pointer
  and uses the productname to get a colorspace
* rename KisImage::profile to KisImage::getProfile to conform to our hacking
  standard.

svn path=/trunk/koffice/; revision=468123
parent 5b07ee95
......@@ -127,8 +127,7 @@ void KisColorSpaceFactoryRegistry::resetProfiles()
}
KisColorSpace * KisColorSpaceFactoryRegistry::getColorSpace(const KisID & csID,
const QString & pName)
KisColorSpace * KisColorSpaceFactoryRegistry::getColorSpace(const KisID & csID, const QString & pName)
{
QString profileName = pName;
......@@ -161,6 +160,13 @@ const QString & pName)
return m_csMap[name];
}
KisColorSpace * KisColorSpaceFactoryRegistry::getColorSpace(const KisID & csID, const KisProfile * profile)
{
return getColorSpace( csID, profile->productName());
}
KisColorSpace * KisColorSpaceFactoryRegistry::getXYZ16()
{
return KisColorSpaceFactoryRegistry::instance()->m_xyzCs;
......
......@@ -73,6 +73,11 @@ public:
*/
KisColorSpace * getColorSpace(const KisID & csID, const QString & profileName);
/**
* Return the colorspace + profile -- where the profile is matched on the name of the specified profile
*/
KisColorSpace * getColorSpace(const KisID & csID, const KisProfile * profile);
/**
* Convenience method to get the often used xyz16 colorspace
*/
......
......@@ -328,8 +328,8 @@ QDomElement KisDoc::saveImage(QDomDocument& doc, KisImageSP img)
image.setAttribute("colorspacename", img -> colorSpace() -> id().id());
image.setAttribute("description", img -> description());
// XXX: Save profile as blob inside the image, instead of the product name.
if (img -> profile() && img -> profile()-> valid())
image.setAttribute("profile", img -> profile() -> productName());
if (img -> getProfile() && img -> getProfile()-> valid())
image.setAttribute("profile", img -> getProfile() -> productName());
image.setAttribute("x-res", img -> xRes());
image.setAttribute("y-res", img -> yRes());
......@@ -650,11 +650,11 @@ bool KisDoc::completeSaving(KoStore *store)
store -> close();
}
}
if ((img) -> profile()) {
if ((img) -> getProfile()) {
location = external ? QString::null : uri;
location += (img) -> name() + "/annotations/icc";
if (store -> open(location)) {
store -> write((img) -> profile() -> annotation() -> annotation());
store -> write((img) -> getProfile() -> annotation() -> annotation());
store -> close();
}
}
......@@ -666,7 +666,7 @@ bool KisDoc::completeSaving(KoStore *store)
QPixmap * pix = new QPixmap(m_currentImage -> width(), m_currentImage -> height());
QPainter gc(pix);
m_currentImage -> renderToPainter(0, 0, m_currentImage -> width(), m_currentImage -> height(), gc, m_currentImage -> profile());
m_currentImage -> renderToPainter(0, 0, m_currentImage -> width(), m_currentImage -> height(), gc, m_currentImage -> getProfile());
gc.end();
QImage composite = pix -> convertToImage();
......
......@@ -36,7 +36,7 @@
#include "kis_image_iface.h"
#include "kis_annotation.h"
#include "kis_colorspace_factory_registry.h"
#include "kis_command.h"
#include "kis_types.h"
#include "kis_guide.h"
......@@ -434,7 +434,6 @@ namespace {
KisImage::KisImage(KisDoc *doc, Q_INT32 width, Q_INT32 height, KisColorSpace * colorSpace, const QString& name)
{
m_profile = 0;
init(doc, width, height, colorSpace, name);
setName(name);
m_dcop = 0L;
......@@ -456,7 +455,6 @@ KisImage::KisImage(const KisImage& rhs) : QObject(), KShared(rhs)
m_colorSpace = rhs.m_colorSpace;
m_dirty = rhs.m_dirty;
m_adapter = rhs.m_adapter;
m_profile = rhs.m_profile;
m_bkg = new KisBackground(this, rhs.width(), rhs.height());
Q_CHECK_PTR(m_bkg);
......@@ -826,8 +824,6 @@ void KisImage::convertTo(KisColorSpace * dstColorSpace, Q_INT32 renderingIntent)
(*it) -> convertTo(dstColorSpace, renderingIntent);
}
setProfile(dstColorSpace -> getProfile());
m_projection->convertTo(dstColorSpace, renderingIntent);
m_bkg->convertTo(dstColorSpace, renderingIntent);
......@@ -845,22 +841,18 @@ void KisImage::convertTo(KisColorSpace * dstColorSpace, Q_INT32 renderingIntent)
notifyLayersChanged();
}
KisProfile * KisImage::profile() const
KisProfile * KisImage::getProfile() const
{
return m_profile;
return colorSpace()->getProfile();
}
void KisImage::setProfile(const KisProfile * profile)
{
// XXX: When we set a new profile, we should do a transform!
if (profile && profile -> valid()) {
m_profile = const_cast<KisProfile *>( profile );
}
else {
m_profile = 0;
}
KisColorSpace * dstSpace = KisColorSpaceFactoryRegistry::instance()->getColorSpace( colorSpace()->id(), profile);
convertTo( dstSpace );
notify();
emit(sigProfileChanged(m_profile));
emit(sigProfileChanged(const_cast<KisProfile *>(profile)));
}
double KisImage::xRes()
......@@ -1756,8 +1748,10 @@ void KisImage::removeAnnotation(QString type)
vKisAnnotationSP_it KisImage::beginAnnotations()
{
if (m_profile) {
addAnnotation(m_profile -> annotation());
KisProfile * profile = colorSpace()->getProfile();
if (profile) {
addAnnotation(profile -> annotation());
} else {
removeAnnotation("icc");
}
......
......@@ -96,7 +96,7 @@ public:
void convertTo(KisColorSpace * dstColorSpace, Q_INT32 renderingIntent = INTENT_PERCEPTUAL);
// Get the profile associated with this image
KisProfile * profile() const;
KisProfile * getProfile() const;
// Set the profile associated with this image
void setProfile(const KisProfile * profile);
......@@ -255,8 +255,6 @@ private:
QString m_name;
QString m_description;
KisProfile * m_profile;
Q_INT32 m_width;
Q_INT32 m_height;
......
......@@ -188,7 +188,6 @@ KisProfile * KisProfile::getScreenProfile (int screen)
return new KisProfile(profile, bytes);
} else {
kdDebug() << "No profile set for X11, not correcting" << endl;
return NULL;
}
#else
......
......@@ -444,13 +444,13 @@ KisLayerSP KisSelectionManager::paste()
gc.end();
KisConfig cfg;
if (cfg.askProfileOnPaste() && clip -> colorSpace() -> getProfile() == 0 && img -> profile() != 0) {
if (cfg.askProfileOnPaste() && clip -> colorSpace() -> getProfile() == 0 && img -> getProfile() != 0) {
KisDlgApplyProfile * dlg = new KisDlgApplyProfile(m_parent);
Q_CHECK_PTR(dlg);
if (dlg -> exec() == QDialog::Accepted) {
KisProfile * profile = dlg -> profile();
if (profile != img -> profile()) {
if (profile != img -> getProfile()) {
layer -> convertTo(img -> colorSpace(), dlg -> renderIntent());
}
}
......
......@@ -433,11 +433,11 @@ void KisView::updateStatusBarProfileLabel()
KisImageSP img = currentImg();
if (!img) return;
if (img -> profile() == 0) {
if (img -> getProfile() == 0) {
m_statusBarProfileLabel -> setText(i18n("No profile"));
}
else {
m_statusBarProfileLabel -> setText(img -> profile() -> productName());
m_statusBarProfileLabel -> setText(img -> getProfile() -> productName());
}
}
......@@ -754,7 +754,7 @@ void KisView::paintView(const KisRect& r)
}
gc.translate((-horzValue()) / zoom(), (-vertValue()) / zoom());
m_doc -> paintContent(gc, wr, monitorProfile(), HDRExposure());
m_doc -> paintContent(gc, wr, m_monitorProfile, HDRExposure());
}
paintGuides();
......@@ -1063,11 +1063,22 @@ void KisView::slotImageProperties()
if (!img) return;
KisDlgImageProperties * dlg = new KisDlgImageProperties(img, this);
Q_CHECK_PTR(dlg);
dlg -> exec();
delete dlg;
KisDlgImageProperties dlg(img, this);
if (dlg.exec() == QDialog::Accepted) {
if (dlg.imageWidth() != img -> width() ||
dlg.imageHeight() != img -> height()) {
resizeCurrentImage(dlg.imageWidth(),
dlg.imageHeight());
}
Q_INT32 opacity = dlg.opacity();
opacity = opacity * 255 / 100;
img -> setName(dlg.imageName());
img -> setResolution(dlg.resolution(), dlg.resolution());
img -> setDescription(dlg.description());
img -> setProfile(dlg.profile());
}
}
void KisView::slotInsertImageAsLayer()
......
......@@ -38,7 +38,6 @@
#include "kis_types.h"
#include "kis_image.h"
#include "kis_config.h"
#include "kis_view.h"
#include "kis_id.h"
#include "kis_cmb_idlist.h"
......@@ -51,8 +50,6 @@ KisDlgImageProperties::KisDlgImageProperties(KisImageSP image, QWidget *parent,
m_image = image;
m_view = (KisView*)parent;
setMainWidget(m_page);
resize(m_page -> sizeHint());
......@@ -73,8 +70,8 @@ KisDlgImageProperties::KisDlgImageProperties(KisImageSP image, QWidget *parent,
fillCmbProfiles(image -> colorSpace() -> id());
if (image -> profile()) {
m_page -> cmbProfile -> setCurrentText(image -> profile() -> productName());
if (image -> getProfile()) {
m_page -> cmbProfile -> setCurrentText(image -> getProfile() -> productName());
}
else {
m_page -> cmbProfile -> setCurrentItem(0);
......@@ -103,31 +100,41 @@ KisDlgImageProperties::~KisDlgImageProperties()
delete m_page;
}
void KisDlgImageProperties::okClicked()
int KisDlgImageProperties::imageWidth()
{
if (m_page -> intWidth -> value() != m_image -> width() ||
m_page -> intHeight -> value() != m_image -> height()) {
m_view -> resizeCurrentImage(m_page -> intWidth -> value(),
m_page -> intHeight -> value());
}
// XXX Convert m_page -> cmbColorSpaces -> currentText ();
// XXX Convert background color
// XXX: Convert opacity of background layer
Q_INT32 opacity = m_page -> sliderOpacity -> value();
opacity = opacity * 255 / 100;
m_image -> setName(m_page -> txtName -> text());
m_image -> setResolution(m_page -> doubleResolution -> value(),
m_page -> doubleResolution -> value());
m_image -> setDescription(m_page -> txtDescription -> text());
return m_page -> intWidth -> value();
}
int KisDlgImageProperties::imageHeight()
{
return m_page -> intHeight -> value();
}
int KisDlgImageProperties::opacity()
{
return m_page -> sliderOpacity -> value();
}
QString KisDlgImageProperties::imageName()
{
return m_page -> txtName -> text();
}
double KisDlgImageProperties::resolution()
{
return m_page -> doubleResolution -> value();
}
QString KisDlgImageProperties::description()
{
return m_page -> txtDescription -> text();
}
KisProfile * KisDlgImageProperties::profile()
{
QValueVector<KisProfile *> profileList = KisColorSpaceFactoryRegistry::instance()->profilesFor( m_image -> colorSpace()->id() );
Q_UINT32 index = m_page -> cmbProfile -> currentItem();
m_image -> setProfile(profileList.at(index));
return profileList.at(index);
}
// XXX: Copy & paste from kis_dlg_create_img -- refactor to separate class
......
......@@ -21,7 +21,6 @@
#include <kdialogbase.h>
class WdgNewImage;
class KisView;
class QButtonGroup;
class KisID;
......@@ -35,17 +34,22 @@ public:
const char *name = 0);
virtual ~KisDlgImageProperties();
int imageWidth();
int imageHeight();
int opacity();
QString imageName();
double resolution();
QString description();
KisProfile * profile();
private slots:
void okClicked();
void fillCmbProfiles(const KisID &);
private:
WdgNewImage * m_page;
KisImageSP m_image;
KisView * m_view;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment