krita

kis_histogram.h

00001 /*
00002  *  Copyright (c) 2004 Boudewijn Rempt
00003  *            (c) 2005 Bart Coppens <kde@bartcoppens.be>
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018  */
00019 #ifndef KIS_HISTOGRAM_
00020 #define KIS_HISTOGRAM_
00021 
00022 #include "kis_types.h"
00023 #include "kis_colorspace.h"
00024 #include "kis_histogram_producer.h"
00025 
00026 enum enumHistogramType {
00027     LINEAR,
00028     LOGARITHMIC
00029 };
00043 class KisHistogram : public KShared {
00044 
00045 public:
00050     class Calculations {
00051 
00052         double m_max, m_min, m_mean, m_total, m_median, m_stddev;
00053 
00054         Q_UINT32 m_high, m_low, m_count;
00055 
00056         friend class KisHistogram;
00057 
00058     public:
00059 
00060         Calculations() : m_max(0.0), m_min(0.0), m_mean(0.0), m_total(0.0), m_median(0.0),
00061             m_stddev(0.0), m_high(0), m_low(0), m_count(0) {}
00066         inline double getMax() { return m_max; }
00071         inline double getMin() { return m_min; }
00073         inline Q_UINT32 getHighest() { return m_high; }
00075         inline Q_UINT32 getLowest() { return m_low; }
00077         inline double getMean() { return m_mean; }
00078         //double getMedian() { return m_median; }
00079         //double getStandardDeviation() { return m_stddev; }
00081         inline Q_UINT32 getCount() { return m_count; }
00083         inline double getTotal() { return m_total; }
00084         //Q_UINT8 getPercentile() { return m_percentile; } // What is this exactly? XXX
00085     };
00086 
00087     KisHistogram(KisPaintLayerSP layer, 
00088                  KisHistogramProducerSP producer,
00089                  const enumHistogramType type);
00090 
00091     KisHistogram(KisPaintDeviceSP paintdev, 
00092                  KisHistogramProducerSP producer,
00093                  const enumHistogramType type);
00094 
00095     virtual ~KisHistogram();
00096 
00098     void updateHistogram();
00099 
00104     void computeHistogram();
00105 
00107     Calculations calculations();
00109     Calculations selectionCalculations();
00110 
00111     inline Q_UINT32 getValue(Q_UINT8 i) { return m_producer->getBinAt(m_channel, i); }
00112 
00113     inline enumHistogramType getHistogramType() { return m_type; }
00114     inline void setHistogramType(enumHistogramType type) { m_type = type; }
00115     inline void setProducer(KisHistogramProducerSP producer) { m_producer = producer; }
00116     inline void setChannel(Q_INT32 channel) { m_channel = channel; }
00117     inline KisHistogramProducerSP producer() { return m_producer; }
00118     inline Q_INT32 channel() { return m_channel; }
00119 
00120     inline bool hasSelection() { return m_selection; }
00121     inline double selectionFrom() { return m_selFrom; }
00122     inline double selectionTo() { return m_selTo; }
00123     inline void setNoSelection() { m_selection = false; }
00125     inline void setSelection(double from, double to)
00126         { m_selection = true; m_selFrom = from; m_selTo = to; }
00127 
00128 
00129 private:
00130     // Dump the histogram to debug.
00131     void dump();
00132     QValueVector<Calculations> calculateForRange(double from, double to);
00133     Calculations calculateSingleRange(int channel, double from, double to);
00134 
00135     KisPaintDeviceSP m_device;
00136     KisHistogramProducerSP m_producer;
00137 
00138     enumHistogramType m_type;
00139 
00140     Q_INT32 m_channel;
00141     double m_selFrom, m_selTo;
00142     bool m_selection;
00143 
00144     KisPaintDeviceSP m_dev;
00145 
00146     QValueVector<Calculations> m_completeCalculations, m_selectionCalculations;
00147 };
00148 
00149 
00150 #endif // KIS_HISTOGRAM_WIDGET_
KDE Home | KDE Accessibility Home | Description of Access Keys