Commit 9b1bbe3a authored by Halla Rempt's avatar Halla Rempt

* The channelinfo is now contained in a KisSharedPtrVector, instead of an array of pointers.

* All alpha settings now devolve onto the color strategies, and almost all of the color
  strategies now support functioning with and without alpha.
* Removed the old channel & mask stubs that were never associated with any meaningful
  implementation. More API cleanups in KisImage.
* Integrated new new image dialog with some new settings (but I still need to add
  those to the loading/saving in kisdoc)

svn path=/trunk/koffice/; revision=368408
parent 91a59f30
......@@ -34,8 +34,6 @@ libkritacore_la_LIBADD = tiles/libkistile.la \
libkritacore_la_SOURCES = kis_paint_device.cc \
kis_layer.cc \
kis_image.cc \
kis_mask.cc \
kis_channel.cc \
kis_doc.cc \
kis_view.cc \
kis_factory.cc \
......@@ -81,8 +79,6 @@ noinst_HEADERS = kis_paint_device.h \
kis_image.h \
kis_doc.h \
kis_view.h \
kis_mask.h \
kis_channel.h \
kis_factory.h \
kis_nameserver.h \
kis_painter.h \
......
......@@ -2,6 +2,7 @@ INCLUDES = -I$(srcdir)/../ \
-I$(srcdir)/../color_strategy \
-I$(srcdir)/../compositeop \
-I$(srcdir)/../visitors/ \
-I$(srcdir)/../resources/ \
-I$(srcdir)/../tiles/ \
-I$(srcdir)/../../ui/ \
-I../../ui/ \
......
......@@ -199,7 +199,7 @@ KisImageBuilder_Result KisImageMagickConverter::decode(const KURL& uri, bool isB
emit notifyProgressError(this);
return KisImageBuilder_RESULT_FAILURE;
}
m_img = new KisImage(m_adapter, 0, 0, KisColorSpaceRegistry::singleton()->colorSpace("RGBA"), m_doc -> nextImageName());
m_img = new KisImage(m_adapter, 0, 0, KisColorSpaceRegistry::instance()->colorSpace("RGBA"), m_doc -> nextImageName());
emit notifyProgressStage(this, i18n("Importing..."), 0);
while ((image = RemoveFirstImageFromList(&images))) {
......
INCLUDES = -I$(srcdir)/.. \
-I$(srcdir)/../tiles \
-I$(srcdir)/../resources \
-I$(srcdir)/../../ui \
$(KOFFICE_INCLUDES) -I$(interfacedir) $(KOPAINTER_INCLUDES) $(all_includes)
......
......@@ -33,18 +33,19 @@
#include "kis_iterators_pixel.h"
#include "kis_selection.h"
#include "kis_channelinfo.h"
#include "kis_types.h"
namespace {
const Q_INT32 MAX_CHANNEL_ALPHA = 1;
}
KisChannelInfo KisColorSpaceAlpha::channelInfo[1] = { KisChannelInfo(i18n("alpha"), 0, ALPHA) };
KisColorSpaceAlpha::KisColorSpaceAlpha() :
KisStrategyColorSpace("alpha mask", TYPE_GRAY_8)
{
m_maskColor = KoColor::white();
m_inverted = false;
m_channels.push_back(new KisChannelInfo(i18n("alpha"), 0, ALPHA));
}
KisColorSpaceAlpha::~KisColorSpaceAlpha()
......@@ -77,13 +78,13 @@ void KisColorSpaceAlpha::toKoColor(const QUANTUM *src, KoColor *c, QUANTUM *opac
}
}
KisChannelInfo* KisColorSpaceAlpha::channels() const
vKisChannelInfoSP KisColorSpaceAlpha::channels() const
{
return channelInfo;
return m_channels;
}
bool KisColorSpaceAlpha::alpha() const
{
return true;
return true; // Of course!
}
Q_INT32 KisColorSpaceAlpha::depth() const
......
......@@ -47,7 +47,7 @@ public:
virtual KisPixelRO toKisPixelRO(QUANTUM *src) { return KisPixelRO (src, src); }
virtual KisPixel toKisPixel(QUANTUM *src) { return KisPixel (src, src); }
virtual KisChannelInfo* channels() const;
virtual vKisChannelInfoSP channels() const;
virtual bool alpha() const;
virtual Q_INT32 depth() const;
virtual Q_INT32 nColorChannels() const { return 0; };
......@@ -69,7 +69,7 @@ protected:
CompositeOp op);
private:
static KisChannelInfo channelInfo[1];
vKisChannelInfoSP m_channels;
KoColor m_maskColor;
bool m_inverted;
......
......@@ -35,7 +35,7 @@ KisColorSpaceRegistry::~KisColorSpaceRegistry()
{
}
KisColorSpaceRegistry* KisColorSpaceRegistry::singleton()
KisColorSpaceRegistry* KisColorSpaceRegistry::instance()
{
if(KisColorSpaceRegistry::m_singleton == 0)
{
......
......@@ -34,7 +34,7 @@ public:
KisStrategyColorSpaceSP colorSpace(const QString& name) const;
QStringList listColorSpaceNames() const;
public:
static KisColorSpaceRegistry* singleton();
static KisColorSpaceRegistry* instance();
private:
KisColorSpaceRegistry();
......
......@@ -24,6 +24,8 @@
#include "kis_global.h"
#include "kis_factory.h"
KisStrategyColorSpace::KisStrategyColorSpace() {}
KisStrategyColorSpace::KisStrategyColorSpace(const QString& name, Q_UINT32 cmType)
: m_name(name),
m_cmType(cmType)
......
......@@ -38,6 +38,7 @@ class KisStrategyColorSpace : public KShared {
public:
KisStrategyColorSpace();
/**
* Create a new colorspace strategy.
*
......@@ -59,10 +60,9 @@ public:
virtual KisPixelRO toKisPixelRO(QUANTUM *src) = 0;
virtual KisPixel toKisPixel(QUANTUM *src) = 0;
// XXX: make this a proper vector. Pointers to arrays are _so_ seventies, and
// Stroustrup assures us a vector is as effecient a mem array anyway.
virtual KisChannelInfo * channels() const = 0;
// Return a vector describing all the channels this color model has.
virtual vKisChannelInfoSP channels() const = 0;
virtual Q_UINT32 colorModelType() { return m_cmType; };
......@@ -110,6 +110,20 @@ public:
Q_INT32 cols,
CompositeOp op);
/**
* Set the icm profile for conversion between color spaces
*
* XXX: make user-definable for certain transforms. Maybe
* only in the switch color space dialog for the whole image.
*/
void setProfile(cmsHPROFILE profile) { m_profile = profile; }
/**
* Get the icm profile for conversion between color spaces.
*/
cmsHPROFILE getProfile() { return m_profile; }
protected:
/**
......@@ -136,24 +150,7 @@ protected:
Q_INT32 cols,
CompositeOp op) = 0;
/**
* Set the icm profile for conversion between color spaces
*
* XXX: make user-definable for certain transforms. Maybe
* only in the switch color space dialog for the whole image.
*/
void setProfile(cmsHPROFILE profile) { m_profile = profile; }
/**
* Get the icm profile for conversion between color spaces.
*/
cmsHPROFILE getProfile() { return m_profile; }
private:
KisStrategyColorSpace(const KisStrategyColorSpace&);
KisStrategyColorSpace& operator=(const KisStrategyColorSpace&);
QString m_name; // The user-friendly name
Q_UINT32 m_cmType; // The colorspace type as defined by littlecms
......@@ -162,6 +159,11 @@ private:
cmsHPROFILE m_profile; // THe default profile for this color strategy
private:
KisStrategyColorSpace(const KisStrategyColorSpace&);
KisStrategyColorSpace& operator=(const KisStrategyColorSpace&);
};
......
/*
* Copyright (c) 2002 Patrick Julien <freak@codepimps.org>
*
* this program is free software; you can redistribute it and/or modify
* it under the terms of the gnu general public license as published by
* the free software foundation; either version 2 of the license, or
* (at your option) any later version.
*
* this program is distributed in the hope that it will be useful,
* but without any warranty; without even the implied warranty of
* merchantability or fitness for a particular purpose. see the
* gnu general public license for more details.
*
* you should have received a copy of the gnu general public license
* along with this program; if not, write to the free software
* foundation, inc., 675 mass ave, cambridge, ma 02139, usa.
*/
#include "kis_global.h"
#include "kis_types.h"
#include "kis_channel.h"
#include "kis_image.h"
#include "kis_colorspace_registry.h"
KisChannel::KisChannel(KisImage *img, Q_INT32 width, Q_INT32 height, const QString& name, const KoColor&)
: super(img, width, height, KisColorSpaceRegistry::singleton()->colorSpace("Grayscale + Alpha"), name)
{
}
KisChannel::KisChannel(const KisChannel& rhs) : super(rhs)
{
}
KisChannel::~KisChannel()
{
}
QUANTUM KisChannel::opacity() const
{
return QUANTUM_MAX;
}
void KisChannel::opacity(QUANTUM)
{
}
/*
* Copyright (c) 2002 Patrick Julien <freak@codepimps.org>
*
* this program is free software; you can redistribute it and/or modify
* it under the terms of the gnu general public license as published by
* the free software foundation; either version 2 of the license, or
* (at your option) any later version.
*
* this program is distributed in the hope that it will be useful,
* but without any warranty; without even the implied warranty of
* merchantability or fitness for a particular purpose. see the
* gnu general public license for more details.
*
* you should have received a copy of the gnu general public license
* along with this program; if not, write to the free software
* foundation, inc., 675 mass ave, cambridge, ma 02139, usa.
*/
#ifndef KIS_CHANNEL_H_
#define KIS_CHANNEL_H_
#include "kis_paint_device.h"
class KisChannel : public KisPaintDevice {
typedef KisPaintDevice super;
public:
KisChannel(KisImage *img, Q_INT32 width, Q_INT32 height, const QString& name, const KoColor& color);
KisChannel(const KisChannel& rhs);
virtual ~KisChannel();
public:
QUANTUM opacity() const;
void opacity(QUANTUM val);
KoColor color() const;
void color(KoColor clr);
KisChannelSP createMask(Q_INT32 w, Q_INT32 h);
bool bounds(QRect& rc);
Q_INT32 value(Q_INT32 x, Q_INT32 y);
bool empty();
void feather();
void clear();
void invert();
void border(Q_INT32 xradius, Q_INT32 yradius);
void grow(Q_INT32 xradius, Q_INT32 yradius);
void shrink(Q_INT32 xradius, Q_INT32 yradius);
void translate(Q_INT32 x, Q_INT32 y);
};
#endif // KIS_CHANNEL_H_
......@@ -19,6 +19,7 @@
#define KIS_CHANNELINFO_H_
#include "qstring.h"
#include "ksharedptr.h"
enum enumChannelType {
COLOR,
......@@ -31,7 +32,7 @@ enum enumChannelType {
* that is, one of the components that makes up a particular
* pixel.
*/
class KisChannelInfo {
class KisChannelInfo : public KShared {
public:
KisChannelInfo() { };
KisChannelInfo( const QString & name, Q_INT32 npos, enumChannelType channelType)
......
......@@ -58,7 +58,6 @@
#include "kis_types.h"
#include "kis_config.h"
#include "kis_global.h"
#include "kis_channel.h"
#include "kis_dlg_create_img.h"
#include "kis_doc.h"
#include "kis_factory.h"
......@@ -67,7 +66,6 @@
#include "kis_nameserver.h"
#include "kis_painter.h"
#include "kis_fill_painter.h"
#include "kis_mask.h"
#include "kis_command.h"
#include "kis_view.h"
#include "builder/kis_builder_subject.h"
......@@ -529,7 +527,6 @@ QDomElement KisDoc::saveImage(QDomDocument& doc, KisImageSP img)
{
QDomElement image = doc.createElement("IMAGE");
vKisLayerSP layers;
vKisChannelSP channels;
Q_ASSERT(img);
image.setAttribute("name", img -> name());
......@@ -548,16 +545,6 @@ QDomElement KisDoc::saveImage(QDomDocument& doc, KisImageSP img)
elem.appendChild(saveLayer(doc, *it));
}
channels = img -> channels();
if (channels.size() > 0) {
QDomElement elem = doc.createElement("CHANNELS");
image.appendChild(elem);
for (vKisChannelSP_it it = channels.begin(); it != channels.end(); it++)
elem.appendChild(saveChannel(doc, *it));
}
// TODO Image colormap if any
return image;
......@@ -623,7 +610,7 @@ KisImageSP KisDoc::loadImage(const QDomElement& element)
return 0;
}
}
img = new KisImage(this, width, height, KisColorSpaceRegistry::singleton()->colorSpace(colorspacename), name);
img = new KisImage(this, width, height, KisColorSpaceRegistry::instance()->colorSpace(colorspacename), name);
for (node = element.firstChild(); !node.isNull(); node = node.nextSibling()) {
if (node.isElement()) {
......@@ -640,15 +627,6 @@ KisImageSP KisDoc::loadImage(const QDomElement& element)
if (img -> nlayers()) {
img -> activateLayer(0);
}
} else if (node.nodeName() == "CHANNELS") {
for (child = node.firstChild(); !child.isNull(); child = child.nextSibling()) {
KisChannelSP channel = loadChannel(child.toElement(), img);
if (!channel)
return 0;
img -> add(channel, -1);
}
} else if (node.nodeName() == "COLORMAP") {
// TODO
} //else {
......@@ -675,7 +653,6 @@ QDomElement KisDoc::saveLayer(QDomDocument& doc, KisLayerSP layer)
layerElement.setAttribute("opacity", layer -> opacity());
layerElement.setAttribute("visible", layer -> visible());
layerElement.setAttribute("linked", layer -> linked());
// TODO : Layer mask
return layerElement;
}
......@@ -742,69 +719,6 @@ KisLayerSP KisDoc::loadLayer(const QDomElement& element, KisImageSP img)
return layer;
}
QDomElement KisDoc::saveChannel(QDomDocument& doc, KisChannelSP channel)
{
QDomElement channelElement = doc.createElement("CHANNEL");
channelElement.setAttribute("name", channel -> name());
channelElement.setAttribute("x", channel -> x());
channelElement.setAttribute("y", channel -> y());
channelElement.setAttribute("width", channel -> width());
channelElement.setAttribute("height", channel -> height());
channelElement.setAttribute("opacity", channel -> opacity());
return channelElement;
}
KisChannelSP KisDoc::loadChannel(const QDomElement& element, KisImageSP img)
{
KisConfig cfg;
QString attr;
QDomNode node;
QDomNode child;
QString name;
Q_INT32 x;
Q_INT32 y;
Q_INT32 width;
Q_INT32 height;
Q_INT32 opacity;
KisChannelSP channel;
if ((name = element.attribute("name")).isNull())
return 0;
if ((attr = element.attribute("x")).isNull())
return 0;
x = attr.toInt();
if ((attr = element.attribute("y")).isNull())
return 0;
y = attr.toInt();
if ((attr = element.attribute("width")).isNull())
return 0;
if ((width = attr.toInt()) < 0 || x + width > cfg.maxImgWidth())
return 0;
if ((attr = element.attribute("height")).isNull())
return 0;
if ((height = attr.toInt()) < 0 || y + height > cfg.maxImgHeight())
return 0;
if ((attr = element.attribute("opacity")).isNull())
return 0;
if ((opacity = attr.toInt()) < 0 || opacity > QUANTUM_MAX)
return 0;
channel = new KisChannel(img, width, height, name, KoColor::black());
channel -> opacity(opacity);
channel -> move(x, y);
return channel;
}
bool KisDoc::completeSaving(KoStore *store)
{
......@@ -816,7 +730,7 @@ bool KisDoc::completeSaving(KoStore *store)
KisImageSP img;
for (vKisImageSP_it it = m_images.begin(); it != m_images.end(); it++) {
totalSteps += (*it) -> nlayers() + (*it) -> nchannels();
totalSteps += (*it) -> nlayers();
img = new KisImage(**it);
img -> setName((*it) -> name());
images.push_back(img);
......@@ -826,7 +740,6 @@ bool KisDoc::completeSaving(KoStore *store)
for (vKisImageSP_it it = images.begin(); it != images.end(); it++) {
vKisLayerSP layers = (*it) -> layers();
vKisChannelSP channels = (*it) -> channels();
for (vKisLayerSP_it it2 = layers.begin(); it2 != layers.end(); it2++) {
connect(*it2, SIGNAL(ioProgress(Q_INT8)), this, SLOT(slotIOProgress(Q_INT8)));
......@@ -844,30 +757,10 @@ bool KisDoc::completeSaving(KoStore *store)
store -> close();
}
// TODO Mask
IOCompletedStep();
(*it2) -> disconnect();
}
for (vKisChannelSP_it it2 = channels.begin(); it2 != channels.end(); it2++) {
connect(*it2, SIGNAL(ioProgress(Q_INT8)), this, SLOT(slotIOProgress(Q_INT8)));
location = external ? QString::null : uri;
location += (*it) -> name() + "/channels/" + (*it2) -> name();
if (store -> open(location)) {
if (!(*it2) -> write(store)) {
(*it2) -> disconnect();
store -> close();
IODone();
return false;
}
store -> close();
}
IOCompletedStep();
(*it2) -> disconnect();
}
}
IODone();
......@@ -882,13 +775,12 @@ bool KisDoc::completeLoading(KoStore *store)
Q_INT32 totalSteps = 0;
for (vKisImageSP_it it = m_images.begin(); it != m_images.end(); it++)
totalSteps += (*it) -> nlayers() + (*it) -> nchannels();
totalSteps += (*it) -> nlayers();
setIOSteps(totalSteps);
for (vKisImageSP_it it = m_images.begin(); it != m_images.end(); it++) {
vKisLayerSP layers = (*it) -> layers();
vKisChannelSP channels = (*it) -> channels();
for (vKisLayerSP_it it2 = layers.begin(); it2 != layers.end(); it2++) {
connect(*it2, SIGNAL(ioProgress(Q_INT8)), this, SLOT(slotIOProgress(Q_INT8)));
......@@ -906,30 +798,10 @@ bool KisDoc::completeLoading(KoStore *store)
store -> close();
}
// TODO Mask
IOCompletedStep();
(*it2) -> disconnect();
}
for (vKisChannelSP_it it2 = channels.begin(); it2 != channels.end(); it2++) {
connect(*it2, SIGNAL(ioProgress(Q_INT8)), this, SLOT(slotIOProgress(Q_INT8)));
location = external ? QString::null : uri;
location += (*it) -> name() + "/channels/" + (*it2) -> name();
if (store -> open(location)) {
if (!(*it2) -> read(store)) {
(*it2) -> disconnect();
store -> close();
IODone();
return false;
}
store -> close();
}
IOCompletedStep();
(*it2) -> disconnect();
}
}
IODone();
......@@ -1075,7 +947,10 @@ void KisDoc::removeImage(const QString& name)
bool KisDoc::slotNewImage()
{
KisConfig cfg;
KisDlgCreateImg dlg(cfg.maxImgWidth(), cfg.defImgWidth(), cfg.maxImgHeight(), cfg.defImgHeight(), "RGBA");
KisDlgCreateImg dlg(cfg.maxImgWidth(), cfg.defImgWidth(),
cfg.maxImgHeight(), cfg.defImgHeight(),
"RGBA",
nextImageName());
if (dlg.exec() == QDialog::Accepted) {
QString name;
......@@ -1085,8 +960,13 @@ bool KisDoc::slotNewImage()
KisLayerSP layer;
KisFillPainter painter;
img = new KisImage(this, dlg.imgWidth(), dlg.imgHeight(), KisColorSpaceRegistry::singleton()->colorSpace(dlg.colorStrategyName()), nextImageName());
img -> setResolution(100.0, 100.0); // XXX needs to be added to dialog
img = new KisImage(this, dlg.imgWidth(),
dlg.imgHeight(),
KisColorSpaceRegistry::instance()->colorSpace(dlg.colorStrategyName()),
dlg.imgName());
img -> setResolution(dlg.imgResolution(), dlg.imgResolution()); // XXX needs to be added to dialog
img -> setDescription(dlg.imgDescription());