krita

kis_histogram_producer.cc

00001 /*
00002  *  Copyright (c) 2005 Bart Coppens <kde@bartcoppens.be>
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 
00019 #include "kis_histogram_producer.h"
00020 #include "kis_basic_histogram_producers.h"
00021 
00022 KisHistogramProducerFactoryRegistry* KisHistogramProducerFactoryRegistry::m_singleton = 0;
00023 
00024 KisHistogramProducerFactoryRegistry::KisHistogramProducerFactoryRegistry() {
00025     Q_ASSERT(KisHistogramProducerFactoryRegistry::m_singleton == 0);
00026 }
00027 
00028 KisHistogramProducerFactoryRegistry::~KisHistogramProducerFactoryRegistry() {
00029 }
00030 
00031 KisHistogramProducerFactoryRegistry* KisHistogramProducerFactoryRegistry::instance() {
00032     if(KisHistogramProducerFactoryRegistry::m_singleton == 0) {
00033         KisHistogramProducerFactoryRegistry::m_singleton
00034                 = new KisHistogramProducerFactoryRegistry();
00035         m_singleton->add( new KisGenericLabHistogramProducerFactory() );
00036     }
00037     return KisHistogramProducerFactoryRegistry::m_singleton;
00038 }
00039 
00040 KisIDList KisHistogramProducerFactoryRegistry::listKeysCompatibleWith(
00041         KisColorSpace* colorSpace) const
00042 {
00043     KisIDList list;
00044     QValueList<float> preferredList;
00045     storageMap::const_iterator it = m_storage.begin();
00046     storageMap::const_iterator endit = m_storage.end();
00047     // O(n^2), can't this be done better? (But preferrably not by looking up the preferredness
00048     // during the sorting...
00049     while( it != endit ) {
00050         if (it->second->isCompatibleWith(colorSpace)) {
00051             float preferred = it->second->preferrednessLevelWith(colorSpace);
00052             QValueList<float>::iterator pit = preferredList.begin();
00053             QValueList<float>::iterator pend = preferredList.end();
00054             KisIDList::iterator lit = list.begin();
00055 
00056             while (pit != pend && preferred <= *pit) {
00057                 ++pit;
00058                 ++lit;
00059             }
00060 
00061             list.insert(lit, it->first);
00062             preferredList.insert(pit, preferred);
00063         }
00064         ++it;
00065     }
00066     return list;
00067 }
KDE Home | KDE Accessibility Home | Description of Access Keys