Commit b6553212 authored by Boudewijn Rempt's avatar Boudewijn Rempt

* Move the colorspaces to their own shared library.

  There are still a few problems, because I made a few mistakes with
  file placing that I can only fix by committing, fixing and commiting.
  Also, the library isn't completely independent of the rest of Krita yet,
  see the TODO.
* Add an uml diagram of the histogram design.
* Add a meta registry -- that needs to be expanded so it becomes a central
  database for all the stuff we have in the myriad of singletons.
* Fix the HACKING file about getters and setters to conform to Qt standards.

svn path=/trunk/koffice/; revision=470933
parent a287d3bd
......@@ -34,7 +34,7 @@ Getter/setter
Krita doesn't use Qt's properties -- yet. If you want to introduce use of
properties, convert any and all classes in Krita before committing.
Getter/setters are named 'getX() for getters and x(int x) for setters. If you
Getter/setters are named 'x() for getters and setX(int x) for setters. If you
come across violations of this rule, change the code.
Note that this does not hold for dialogs: getter in dialogs
......
INCLUDES = -I$(srcdir)/sdk \
INCLUDES = -I$(srcdir)/sdk -I$(srcdir)/libkritacolor/color_strategy -I$(srcdir)/libkritacolor \
$(KOFFICE_INCLUDES) -I$(interfacedir) $(KOPAINTER_INCLUDES) $(all_includes)
## The common lib, shared between the part, the plugins, and the filters
lib_LTLIBRARIES = libkritacommon.la
libkritacommon_la_SOURCES = dummycommon.cc
libkritacommon_la_LDFLAGS = $(all_libraries) -version-info 1:0 -no-undefined
libkritacommon_la_LIBADD = sdk/libkissdk.la core/libkritacore.la ui/libkisui.la $(LCMS_LIBS) $(LIB_KOFFICEUI) $(LIB_KOPAINTER) $(LIB_KOPALETTE) $(LIB_XINPUTEXT)
libkritacommon_la_LIBADD = sdk/libkissdk.la core/libkritacore.la ui/libkisui.la libkritacolor/libkritacolor.la $(LCMS_LIBS) $(LIB_KOFFICEUI) $(LIB_KOPAINTER) $(LIB_KOPALETTE) $(LIB_XINPUTEXT)
## The part
kde_module_LTLIBRARIES = libkritapart.la
libkritapart_la_SOURCES = krita_part_init.cc
libkritapart_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN)
libkritapart_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN)
libkritapart_la_LIBADD = libkritacommon.la
METASOURCES = AUTO
......@@ -32,7 +32,7 @@ kdemimedir = $(kde_mimedir)/application
rcdir = $(kde_datadir)/krita
rc_DATA = krita.rc krita_readonly.rc
SUBDIRS = sdk ui core . dtd paintops tools modules plugins data pics
SUBDIRS = sdk libkritacolor ui core . dtd paintops tools modules plugins data pics
# Needed to compile libkritacommon.la, which has no source files to itself
# but everything in static libs.
......
......@@ -79,6 +79,7 @@ Colorspace independence (found with the test colorstrategy)
* Check and double check the cms capabilities: especially the use of
profiles in the render/convert/edit paths.
* Merge grayscale layers back into one color image.
* Floodfill is not cs independent -- or if its, cmyk floodfill is broken.
Core
......
# all_includes must remain last!
INCLUDES = \
-I$(srcdir)/../sdk \
-I$(srcdir)/color_strategy \
-I$(srcdir)/tiles \
-I$(srcdir)/../libkritacolor \
-I$(srcdir)/../libkritacolor/color_strategy \
-I$(srcdir)/../ui \
-I../ui \
$(KOFFICE_INCLUDES) \
-I$(interfacedir) \
$(KOPAINTER_INCLUDES) \
$(OPENEXR_CFLAGS) \
$(all_includes)
#CXXFLAGS = -shared -fPIC
......@@ -15,10 +17,9 @@ INCLUDES = \
noinst_LTLIBRARIES = libkritacore.la
libkritacore_la_LIBADD = tiles/libkistile.la \
color_strategy/libkiscolor_strategy.la \
$(LIB_KOPAINTER)
$(LIB_KOPAINTER) $(OPENEXR_LIBS)
libkritacore_la_SOURCES = kis_color.cc kis_paint_device_impl.cc kis_layer.cc \
libkritacore_la_SOURCES = kis_paint_device_impl.cc kis_layer.cc \
kis_image.cc kis_doc.cc kis_view.cc kis_factory.cc kis_nameserver.cc \
kis_painter.cc kis_fill_painter.cc kis_gradient_painter.cc \
kis_convolution_painter.cc kis_cursor.cc kis_selection.cc kis_command.cc kis_background.cc \
......@@ -29,7 +30,7 @@ libkritacore_la_SOURCES = kis_color.cc kis_paint_device_impl.cc kis_layer.cc \
kis_clipboard.cc kis_filter.cc kis_filter_registry.cc kis_filter_strategy.cc \
kis_part_layer.cc kis_filter_manager.cc kis_tool_manager.cc \
kis_paint_device_iface.cc kis_paint_device_iface.skel kis_histogram.cc \
kis_boundary.cc kis_histogram_producer.cc kis_paintop.cc kis_paintop_registry.cc \
kis_boundary.cc kis_paintop.cc kis_paintop_registry.cc \
kis_strategy_move.cc \
kis_tool.cc \
kis_tool_dummy.cc \
......@@ -46,10 +47,9 @@ libkritacore_la_SOURCES = kis_color.cc kis_paint_device_impl.cc kis_layer.cc \
kis_imagepipe_brush.cc \
kis_palette.cc \
kis_pattern.cc \
kis_profile.cc \
kis_resource.cc \
kis_resourceserver.cc \
kis_iterator.cc
kis_iterator.cc kis_meta_registry.cc
noinst_HEADERS = kis_paint_device_impl.h kis_layer.h kis_image.h kis_doc.h \
......@@ -60,7 +60,7 @@ noinst_HEADERS = kis_paint_device_impl.h kis_layer.h kis_image.h kis_doc.h \
kis_selection_manager.h kis_scale_visitor.h kis_rotate_visitor.h \
kis_filter.h kis_filter_registry.h kis_part_layer.h \
kis_filter_manager.h kis_tool_manager.h kis_histogram.h \
kis_paint_device_iface.h kis_boundary.h kis_histogram_producer.h kis_paintop_registry.h kis_paintop.h \
kis_paint_device_iface.h kis_boundary.h kis_paintop_registry.h kis_paintop.h \
kis_strategy_move.h \
kis_tool_shape.h \
kis_tool_registry.h \
......@@ -73,7 +73,6 @@ noinst_HEADERS = kis_paint_device_impl.h kis_layer.h kis_image.h kis_doc.h \
kis_tool.h \
kis_resourceserver.h \
kis_resource.h \
kis_profile.h \
kis_pattern.h \
kis_palette.h \
kis_imagepipe_brush.h \
......@@ -92,5 +91,5 @@ if include_kunittest_tests
TESTSDIR = tests
endif
SUBDIRS = tiles color_strategy . $(TESTSDIR)
SUBDIRS = tiles . $(TESTSDIR)
......@@ -26,13 +26,12 @@
#include "kis_global.h"
#include "kis_types.h"
/**
* KisAlphaMask is intended to create alpha values from a QImage for use
* in brush creation. It is not a generic alpha mask that can be used with
* KisPaintDeviceImpls: use a KisSelection for that.
*/
class KRITACORE_EXPORT KisAlphaMask : public KShared {
class KisAlphaMask : public KShared {
public:
/**
......
......@@ -40,6 +40,8 @@
#include <kdebug.h>
#include <klocale.h>
#include "kis_factory.h"
#include <kis_meta_registry.h>
#include "kis_layer.h"
#include "kis_global.h"
#include "kis_brush.h"
......@@ -1123,7 +1125,7 @@ void KisBrush::setHeight(Q_INT32 h)
}
QImage KisBrush::outline(double pressure) {
KisLayerSP layer = image(KisColorSpaceFactoryRegistry::instance()->getColorSpace(KisID("RGBA",""),""),
KisLayerSP layer = image(KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA",""),""),
KisPaintInformation(pressure));
KisBoundary bounds(layer.data());
int w = maskWidth(pressure);
......@@ -1142,10 +1144,10 @@ void KisBrush::generateBoundary() {
int h = maskHeight(KisPaintInformation());
if (brushType() == IMAGE || brushType() == PIPE_IMAGE) {
layer = image(KisColorSpaceFactoryRegistry::instance()->getColorSpace(KisID("RGBA",""),""), KisPaintInformation());
layer = image(KisMetaRegistry::instance()->csRegistry() ->getColorSpace(KisID("RGBA",""),""), KisPaintInformation());
} else {
KisAlphaMaskSP amask = mask(KisPaintInformation());
KisColorSpace* cs = KisColorSpaceFactoryRegistry::instance()->getColorSpace(KisID("RGBA",""),"");
KisColorSpace* cs = KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA",""),"");
layer = new KisLayer(cs, "temp");
for (int y = 0; y < h; y++) {
KisHLineIteratorPixel it = layer -> createHLineIterator(0, y, w, true);
......
......@@ -17,7 +17,8 @@
*/
#include <qapplication.h>
#include <qclipboard.h>
#include "qobject.h"
#include <qobject.h>
#include <qimage.h>
#include "kdebug.h"
......@@ -25,7 +26,8 @@
#include "kis_paint_device_impl.h"
#include "kis_config.h"
#include "kis_colorspace_factory_registry.h"
#include "kis_factory.h"
#include <kis_meta_registry.h>
#include "kis_clipboard.h"
KisClipboard *KisClipboard::m_singleton = 0;
......@@ -70,7 +72,7 @@ void KisClipboard::setClip(KisPaintDeviceImplSP selection)
// XXX: Is this a performance problem?
KisConfig cfg;
QString monitorProfileName = cfg.monitorProfile();
KisProfile * monitorProfile = KisColorSpaceFactoryRegistry::instance() -> getProfileByName(monitorProfileName);
KisProfile * monitorProfile = KisMetaRegistry::instance()->csRegistry() -> getProfileByName(monitorProfileName);
qimg = selection -> convertToQImage(monitorProfile);
}
else {
......@@ -95,7 +97,7 @@ void KisClipboard::clipboardDataChanged()
QImage qimg = cb -> image();
if (!qimg.isNull()) {
KisColorSpace * cs = KisColorSpaceFactoryRegistry::instance()->getColorSpace(KisID("RGBA",""),"");
KisColorSpace * cs = KisMetaRegistry::instance()->csRegistry() ->getColorSpace(KisID("RGBA",""),"");
m_clip =
new KisPaintDeviceImpl(cs,
......@@ -109,7 +111,7 @@ void KisClipboard::clipboardDataChanged()
}
bool KisClipboard::hasClip()
bool KisClipboard::hasClip()
{
if (m_clip != 0) {
return true;
......
/* This file is part of the KDE project
* Copyright (C) 2005 Boudewijn Rempt <boud@valdyas.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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef _KIS_COLOR_IFACE_H
#define _KIS_COLOR_IFACE_H
#include <dcopref.h>
#include <dcopobj.h>
#include <qstring.h>
class KisColor;
class KisColorIface : virtual public DCOPObject
{
K_DCOP
public:
KisColorIface( KisColor * parent );
k_dcop:
/**
* Returns a byte array that represents one pixel of the current
* color. This can be interpreted by the correct color strategy
*
* @returns the pixel data
*/
QByteArray data();
/**
* Returns the native color model of this color
*
* @returns the colormodel
*/
DCOPRef colorSpace();
/**
* @returns the icc profile of tthis color
*/
DCOPref profile();
/**
* Convert this color to the equivalent color in the other colorspace
*
* @param cs the new colorspace
* @param profile the new profile. This may be 0
*/
void convertTo(DCOPRef cs, DCOPRef profile);
/**
* Replace the existing colordata with the specified data in the
* specified colorspace; if the data and the colorspace don't fit...
*
* @param data the bytes that make up the color
* @param cs the new colorspace
* @param profile the new profile. This may be 0
*/
void setColor(QByteArray data, DCOPRef cs, DCOPRef profile);
/**
* Create a QColor from the current color
*/
QColor toQColor();
/**
* Retrieve the opacitiy level of the current color, normalized
* to a byte.
*/
Q_UINT8 opacity();
private:
KisColor *m_parent;
};
#endif
......@@ -52,6 +52,7 @@
#include <kocommandhistory.h>
// Local
#include <kis_meta_registry.h>
#include "kis_annotation.h"
#include "kis_types.h"
#include "kis_config.h"
......@@ -405,10 +406,10 @@ KisImageSP KisDoc::loadImage(const QDomElement& element)
if ((profileProductName = element.attribute("profile")).isNull()) {
// no mention of profile so get default profile
cs = KisColorSpaceFactoryRegistry::instance() -> getColorSpace(colorspacename,"");
cs = KisMetaRegistry::instance()->csRegistry() -> getColorSpace(colorspacename,"");
}
else {
cs = KisColorSpaceFactoryRegistry::instance() -> getColorSpace(colorspacename, profileProductName);
cs = KisMetaRegistry::instance()->csRegistry() -> getColorSpace(colorspacename, profileProductName);
}
if (cs == 0) {
......@@ -559,10 +560,10 @@ KisLayerSP KisDoc::loadLayer(const QDomElement& element, KisImageSP img)
{
if ((profileProductName = element.attribute("profile")).isNull()) {
// no mention of profile so get default profile
cs = KisColorSpaceFactoryRegistry::instance() -> getColorSpace(colorspacename,"");
cs = KisMetaRegistry::instance()->csRegistry() -> getColorSpace(colorspacename,"");
}
else {
cs = KisColorSpaceFactoryRegistry::instance() -> getColorSpace(colorspacename, profileProductName);
cs = KisMetaRegistry::instance()->csRegistry() -> getColorSpace(colorspacename, profileProductName);
}
if (cs == 0) {
......@@ -784,10 +785,11 @@ KisImageSP KisDoc::newImage(const QString& name, Q_INT32 width, Q_INT32 height,
KisLayerSP layer = new KisLayer(img, img -> nextLayerName(), OPACITY_OPAQUE);
Q_CHECK_PTR(layer);
KisColorSpace * cs = KisMetaRegistry::instance()->csRegistry()->getRGB8();
KisFillPainter painter;
painter.begin(layer.data());
painter.fillRect(0, 0, width, height, Qt::white, OPACITY_OPAQUE);
painter.fillRect(0, 0, width, height, KisColor(Qt::white, cs), OPACITY_OPAQUE);
painter.end();
img -> add(layer, -1);
......@@ -813,7 +815,7 @@ bool KisDoc::slotNewImage()
KisImageSP img;
KisLayerSP layer;
KisColorSpace * cs = KisColorSpaceFactoryRegistry::instance()->getColorSpace(dlg.colorSpaceID(), dlg.profileName());
KisColorSpace * cs = KisMetaRegistry::instance()->csRegistry()->getColorSpace(dlg.colorSpaceID(), dlg.profileName());
if (!cs) return false;
......@@ -862,7 +864,7 @@ void KisDoc::paintContent(QPainter& painter, const QRect& rect, bool /*transpare
// XXX: Use transparent flag to forego the background layer
KisConfig cfg;
QString monitorProfileName = cfg.monitorProfile();
KisProfile * profile = KisColorSpaceFactoryRegistry::instance() -> getProfileByName(monitorProfileName);
KisProfile * profile = KisMetaRegistry::instance()->csRegistry() -> getProfileByName(monitorProfileName);
painter.scale(zoomX, zoomY);
paintContent(painter, rect, profile);
......
......@@ -22,6 +22,7 @@
#include <qstringlist.h>
#include <qthread.h>
#include <qdir.h>
#include <kdebug.h>
#include <kinstance.h>
......@@ -34,23 +35,20 @@
#include <ktrader.h>
#include <kparts/componentfactory.h>
#include "kis_factory.h"
#include "kis_aboutdata.h"
#include "kis_resourceserver.h"
#include "kis_colorspace_factory_registry.h"
#include "kis_paintop_registry.h"
#include "kis_filter_registry.h"
#include "kis_tool_registry.h"
#include "kis_doc.h"
#include "kis_brush.h"
#include "kis_imagepipe_brush.h"
#include "kis_gradient.h"
#include "kis_pattern.h"
#include "kis_palette.h"
#include <kogradientmanager.h>
#include "kis_factory.h"
KAboutData* KisFactory::s_aboutData = 0;
KInstance* KisFactory::s_instance = 0;
......@@ -88,6 +86,7 @@ KisFactory::KisFactory( QObject* parent, const char* name )
{
s_aboutData = newKritaAboutData();
(void)instance();
s_rserverRegistry = new KisResourceServerRegistry();
......@@ -97,41 +96,47 @@ KisFactory::KisFactory( QObject* parent, const char* name )
KisResourceServer<KisBrush>* brushServer = new KisResourceServer<KisBrush>("kis_brushes", fileExtensions);
ResourceLoaderThread t1 (brushServer);
t1.start();
s_rserverRegistry -> add( KisID( "BrushServer", ""), brushServer );
fileExtensions.clear();
fileExtensions << "*.gih";
KisResourceServer<KisImagePipeBrush>* imagePipeBrushServer = new KisResourceServer<KisImagePipeBrush>("kis_brushes", fileExtensions);
ResourceLoaderThread t2 (imagePipeBrushServer);
t2.start();
s_rserverRegistry -> add( KisID( "ImagePipeBrushServer", ""), imagePipeBrushServer );
fileExtensions.clear();
fileExtensions << "*.pat";
KisResourceServer<KisPattern>* patternServer = new KisResourceServer<KisPattern>("kis_patterns", fileExtensions);
ResourceLoaderThread t3 (patternServer);
t3.start();
s_rserverRegistry -> add( KisID( "PatternServer", ""), patternServer );
fileExtensions.clear();
fileExtensions = KoGradientManager::filters();
KisResourceServer<KisGradient>* gradientServer = new KisResourceServer<KisGradient>("kis_gradients", fileExtensions);
ResourceLoaderThread t4 (gradientServer);
t4.start();
s_rserverRegistry -> add( KisID( "GradientServer", ""), gradientServer );
fileExtensions.clear();
fileExtensions << "*.gpl" << "*.pal" << "*.act";
KisResourceServer<KisPalette>* paletteServer = new KisResourceServer<KisPalette>("kis_palettes", fileExtensions);
ResourceLoaderThread t5 (paletteServer);
t5.start();
t1.wait();
t2.wait();
t3.wait();
t4.wait();
t5.wait();
s_rserverRegistry -> add( KisID( "BrushServer", ""), brushServer );
s_rserverRegistry -> add( KisID( "ImagePipeBrushServer", ""), imagePipeBrushServer );
s_rserverRegistry -> add( KisID( "PatternServer", ""), patternServer );
s_rserverRegistry -> add( KisID( "GradientServer", ""), gradientServer );
s_rserverRegistry -> add( KisID( "PaletteServer", ""), paletteServer );
// Load extension modules and plugins
KisToolRegistry::instance();
KisPaintOpRegistry::instance();
KisFilterRegistry::instance();
KisColorSpaceFactoryRegistry::instance();
// Load all modules: color models, paintops, filters
KTrader::OfferList offers = KTrader::self() -> query(QString::fromLatin1("Krita/CoreModule"),
......@@ -150,11 +155,6 @@ KisFactory::KisFactory( QObject* parent, const char* name )
kdDebug(DBG_AREA_PLUGINS) << "found plugin " << service -> property("Name").toString() << "\n";
}
t1.wait();
t2.wait();
t3.wait();
t4.wait();
t5.wait();
}
KisFactory::~KisFactory()
......@@ -186,6 +186,12 @@ KParts::Part* KisFactory::createPartObject( QWidget *parentWidget,
return doc;
}
KAboutData* KisFactory::aboutData()
{
return s_aboutData;
}
KInstance* KisFactory::instance()
{
if ( !s_instance )
......@@ -232,14 +238,10 @@ KInstance* KisFactory::instance()
return s_instance;
}
KAboutData* KisFactory::aboutData()
{
return s_aboutData;
}
KisResourceServerRegistry* KisFactory::rServerRegistry()
{
return s_rserverRegistry;
}
#include "kis_factory.moc"
......@@ -21,17 +21,20 @@
#ifndef __kis_factory_h__
#define __kis_factory_h__
#include <qptrlist.h>
#include <kparts/plugin.h>
#include <koFactory.h>
#include "kis_generic_registry.h"
#include <koffice_export.h>
class KInstance;
class KisResourceServerBase;
class KAboutData;
typedef KisGenericRegistry<KisResourceServerBase*> KisResourceServerRegistry;
class KRITACORE_EXPORT KisFactory : public KoFactory
......@@ -51,12 +54,14 @@ public:
static KAboutData *aboutData();
static KInstance *instance();
static KisResourceServerRegistry *rServerRegistry();
private:
static KInstance *s_instance;
static KAboutData *s_aboutData;
static KisResourceServerRegistry *s_rserverRegistry;
static KInstance *s_instance;
static KAboutData *s_aboutData;
static KisResourceServerRegistry *s_rserverRegistry;
};
#endif
......@@ -21,7 +21,9 @@
#include <qrect.h>
#include "kis_meta_registry.h"
#include "kis_color.h"
#include "kis_colorspace_factory_registry.h"
#include "kis_painter.h"
#include "kis_types.h"
#include <koffice_export.h>
......@@ -135,14 +137,16 @@ void KisFillPainter::fillRect(const QRect& rc, const KisColor& c)
inline
void KisFillPainter::eraseRect(Q_INT32 x1, Q_INT32 y1, Q_INT32 w, Q_INT32 h)
{
KisColor c(Qt::black);
KisColorSpace * cs = KisMetaRegistry::instance()->csRegistry()->getRGB8();
KisColor c(Qt::black, cs);
fillRect(x1, y1, w, h, c, OPACITY_TRANSPARENT);
}
inline
void KisFillPainter::eraseRect(const QRect& rc)
{
KisColor c(Qt::black);
KisColorSpace * cs = KisMetaRegistry::instance()->csRegistry()->getRGB8();
KisColor c(Qt::black, cs);
fillRect(rc.x(), rc.y(), rc.width(), rc.height(), c, OPACITY_TRANSPARENT);
}
......
......@@ -27,8 +27,8 @@
#include "kis_colorspace.h"
KisHistogram::KisHistogram(KisLayerSP layer,
KisHistogramProducerSP producer,
const enumHistogramType type)
KisHistogramProducerSP producer,
const enumHistogramType type)
{
m_dev = layer.data();
m_type = type;
......@@ -68,7 +68,12 @@ void KisHistogram::updateHistogram()
// Let the producer do it's work
m_producer -> clear();
m_producer -> addRegionToBin(srcIt, cs);
int i;
while ( !srcIt.isDone() ) {
i = srcIt.nConseqPixels();
m_producer -> addRegionToBin(srcIt.rawData(), srcIt.selectionMask(), i, cs);
srcIt += i;
}
//kdDebug() << t.elapsed() << "ms for histogram (new version)" << endl;
......
......@@ -852,7 +852,7 @@ KisProfile * KisImage::getProfile() const
void KisImage::setProfile(const KisProfile * profile)
{
KisColorSpace * dstSpace = KisColorSpaceFactoryRegistry::instance()->getColorSpace( colorSpace()->id(), profile);
KisColorSpace * dstSpace = KisMetaRegistry::instance()->csRegistry()->getColorSpace( colorSpace()->id(), profile);
convertTo( dstSpace );
notify();
......@@ -1714,9 +1714,6 @@ void KisImage::setColorSpace(KisColorSpace * colorSpace)