chalk

kis_histogram_producer.cpp
1/*
2 * Copyright (c) 2005 Bart Coppens <kde@bartcoppens.be>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19#include "kis_histogram_producer.h"
20#include "kis_basic_histogram_producers.h"
21
22KisHistogramProducerFactoryRegistry* KisHistogramProducerFactoryRegistry::m_singleton = 0;
23
24KisHistogramProducerFactoryRegistry::KisHistogramProducerFactoryRegistry() {
25 Q_ASSERT(KisHistogramProducerFactoryRegistry::m_singleton == 0);
26}
27
28KisHistogramProducerFactoryRegistry::~KisHistogramProducerFactoryRegistry() {
29}
30
31KisHistogramProducerFactoryRegistry* KisHistogramProducerFactoryRegistry::instance() {
32 if(KisHistogramProducerFactoryRegistry::m_singleton == 0) {
33 KisHistogramProducerFactoryRegistry::m_singleton
34 = new KisHistogramProducerFactoryRegistry();
35 m_singleton->add( new KisGenericLabHistogramProducerFactory() );
36 }
37 return KisHistogramProducerFactoryRegistry::m_singleton;
38}
39
40KisIDList KisHistogramProducerFactoryRegistry::listKeysCompatibleWith(
41 KisColorSpace* colorSpace) const
42{
43 KisIDList list;
44 TQValueList<float> preferredList;
45 storageMap::const_iterator it = m_storage.begin();
46 storageMap::const_iterator endit = m_storage.end();
47 // O(n^2), can't this be done better? (But preferrably not by looking up the preferredness
48 // during the sorting...
49 while( it != endit ) {
50 if (it->second->isCompatibleWith(colorSpace)) {
51 float preferred = it->second->preferrednessLevelWith(colorSpace);
52 TQValueList<float>::iterator pit = preferredList.begin();
53 TQValueList<float>::iterator pend = preferredList.end();
54 KisIDList::iterator lit = list.begin();
55
56 while (pit != pend && preferred <= *pit) {
57 ++pit;
58 ++lit;
59 }
60
61 list.insert(lit, it->first);
62 preferredList.insert(pit, preferred);
63 }
64 ++it;
65 }
66 return list;
67}
A colorspace is the definition of a certain color model in Chalk.