Commit 2c8b54e8 authored by Patrick Julien's avatar Patrick Julien

first part of implementing flyweights for color space strategies.

svn path=/trunk/koffice/; revision=261852
parent 599183fd
# all_includes must remain last!
INCLUDES = -I$(srcdir)/builder/ -I$(srcdir)/visitors/ -I$(srcdir)/helper/ -I$(srcdir)/tiles/ -I$(srcdir)/../ui -I$(srcdir)/../tools $(KOFFICE_INCLUDES) \
-I$(interfacedir) $(KOPAINTER_INCLUDES) -I$(srcdir)/strategy/ $(all_includes)
-I$(interfacedir) $(KOPAINTER_INCLUDES) -I$(srcdir)/strategy/ $(all_includes) -I$(srcdir)/color_strategy
noinst_LTLIBRARIES = libkiscore.la
libkiscore_la_LIBADD = tiles/libkistile.la helper/libkishelper.la builder/libkiscorebuilder.la strategy/libkisstrategy.la
libkiscore_la_LIBADD = tiles/libkistile.la helper/libkishelper.la builder/libkiscorebuilder.la strategy/libkisstrategy.la color_strategy/libkiscolor_strategy.la
libkiscore_la_SOURCES = kis_paint_device.cc kis_layer.cc kis_channel.cc kis_mask.cc kis_image.cc kis_doc.cc\
kis_view.cc kis_factory.cc kis_pluginserver.cc kis_resourceserver.cc \
kis_brush.cc kis_krayon.cc kis_pattern.cc kis_nameserver.cc \
......@@ -14,5 +14,5 @@ libkiscore_la_SOURCES = kis_paint_device.cc kis_layer.cc kis_channel.cc kis_mask
libkiscore_la_METASOURCES = AUTO
libkiscore_la_LDFLAGS = $(KDE_RPATH)
SUBDIRS = helper tiles builder strategy
SUBDIRS = helper tiles builder strategy color_strategy
INCLUDES = -I$(srcdir)/.. $(KOFFICE_INCLUDES) -I$(interfacedir) $(KOPAINTER_INCLUDES) $(all_includes)
noinst_LTLIBRARIES = libkiscolor_strategy.la
libkiscolor_strategy_la_SOURCES = kis_strategy_colorspace.cc \
kis_strategy_colorspace_rgb.cc \
kis_strategy_colorspace_cmyk.cc \
kis_colorspace_factory.cc \
kis_colorspace_factory_flyweight.cc
libkiscolor_strategy_la_METASOURCES = AUTO
/*
* Copyright (c) 2003 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "kis_colorspace_factory.h"
KisColorSpaceFactoryInterface *KisColorSpaceFactoryInterface::m_singleton = 0;
KisColorSpaceFactoryInterface::KisColorSpaceFactoryInterface()
{
Q_ASSERT(KisColorSpaceFactoryInterface::m_singleton == 0);
KisColorSpaceFactoryInterface::m_singleton = this;
}
KisColorSpaceFactoryInterface::~KisColorSpaceFactoryInterface()
{
}
KisColorSpaceFactoryInterface *KisColorSpaceFactoryInterface::singleton()
{
Q_ASSERT(KisColorSpaceFactoryInterface::m_singleton);
return KisColorSpaceFactoryInterface::m_singleton;
}
/*
* Copyright (c) 2003 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#if !defined KIS_COLORSPACE_FACTORY_H_
#define KIS_COLORSPACE_FACTORY_H_
#include "kis_global.h"
#include "kis_types.h"
class KisColorSpaceFactoryInterface {
public:
KisColorSpaceFactoryInterface();
virtual ~KisColorSpaceFactoryInterface();
public:
virtual KisStrategyColorSpaceSP create(const KisPaintDeviceSP& device) = 0;
virtual KisStrategyColorSpaceSP create(enumImgType imgType) = 0;
public:
static KisColorSpaceFactoryInterface *singleton();
private:
KisColorSpaceFactoryInterface(const KisColorSpaceFactoryInterface&);
KisColorSpaceFactoryInterface operator=(const KisColorSpaceFactoryInterface&);
private:
static KisColorSpaceFactoryInterface *m_singleton;
};
#endif // KIS_COLORSPACE_FACTORY_H_
/*
* Copyright (c) 2003 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdlib.h>
#include <kdebug.h>
#include "kis_colorspace_factory_flyweight.h"
#include "kis_paint_device.h"
#include "kis_strategy_colorspace_cmyk.h"
#include "kis_strategy_colorspace_rgb.h"
KisColorSpaceFactoryFlyweight::KisColorSpaceFactoryFlyweight()
{
}
KisColorSpaceFactoryFlyweight::~KisColorSpaceFactoryFlyweight()
{
}
KisStrategyColorSpaceSP KisColorSpaceFactoryFlyweight::create(const KisPaintDeviceSP& device)
{
KisStrategyColorSpaceSP p;
if (device)
p = create(device -> type());
return p;
}
KisStrategyColorSpaceSP KisColorSpaceFactoryFlyweight::create(enumImgType imgType)
{
KisStrategyColorSpaceSP p = find(imgType);
if (p)
return p;
switch (imgType) {
case IMAGE_TYPE_RGB:
p = new KisStrategyColorSpaceRGB;
break;
case IMAGE_TYPE_CMYK:
p = new KisStrategyColorSpaceCMYK;
break;
default:
kdDebug() << "Color space strategy not implemented." << endl;
abort();
break;
}
m_flyweights[imgType] = p;
return p;
}
KisStrategyColorSpaceSP KisColorSpaceFactoryFlyweight::find(enumImgType imgType) const
{
KisStrategyColorSpaceSP p;
acFlyweights_cit it = m_flyweights.find(imgType);
if (it != m_flyweights.end()) {
p = it -> second;
Q_ASSERT(p);
}
return p;
}
/*
* Copyright (c) 2003 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#if !defined KIS_COLORSPACE_FACTORY_FLYWEIGHT_H_
#define KIS_COLORSPACE_FACTORY_FLYWEIGHT_H_
#include <map>
#include "kis_colorspace_factory.h"
class KisColorSpaceFactoryFlyweight : public KisColorSpaceFactoryInterface {
typedef KisColorSpaceFactoryInterface super;
typedef std::map<enumImgType, KisStrategyColorSpaceSP> acFlyweights;
typedef acFlyweights::iterator acFlyweights_it;
typedef acFlyweights::const_iterator acFlyweights_cit;
public:
KisColorSpaceFactoryFlyweight();
virtual ~KisColorSpaceFactoryFlyweight();
public:
virtual KisStrategyColorSpaceSP create(const KisPaintDeviceSP& device);
virtual KisStrategyColorSpaceSP create(enumImgType imgType);
private:
KisStrategyColorSpaceSP find(enumImgType imgType) const;
private:
acFlyweights m_flyweights;
};
#endif // KIS_COLORSPACE_FACTORY_FLYWEIGHT_H_
......@@ -71,9 +71,9 @@
#include "builder/kis_builder_subject.h"
#include "builder/kis_builder_monitor.h"
#include "builder/kis_image_magick_converter.h"
#include "strategy/kis_strategy_colorspace.h"
#include "strategy/kis_strategy_colorspace_rgb.h"
#include "strategy/kis_strategy_colorspace_cmyk.h"
#include "color_strategy/kis_strategy_colorspace.h"
#include "color_strategy/kis_strategy_colorspace_rgb.h"
#include "color_strategy/kis_strategy_colorspace_cmyk.h"
#include "tiles/kistilemgr.h"
static const char *CURRENT_DTD_VERSION = "1.3";
......
......@@ -2,6 +2,6 @@ INCLUDES = -I$(srcdir)/.. $(KOFFICE_INCLUDES) -I$(interfacedir) $(KOPAINTER_INC
noinst_LTLIBRARIES = libkisstrategy.la
libkisstrategy_la_SOURCES = kis_strategy_move.cc kis_strategy_colorspace.cc kis_strategy_colorspace_rgb.cc kis_strategy_colorspace_cmyk.cc
libkisstrategy_la_SOURCES = kis_strategy_move.cc
libkisstrategy_la_METASOURCES = AUTO
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