00001
00002
00003
00004
00005
00006
00007 #include "ColorFilter.h"
00008 #include "DlgFilterWorker.h"
00009 #include "Logger.h"
00010 #include <QImage>
00011
00012 const int NO_DELAY = 0;
00013 const int COLUMNS_PER_PIECE = 5;
00014
00015 DlgFilterWorker::DlgFilterWorker(const QPixmap &pixmapOriginal,
00016 QRgb rgbBackground) :
00017 m_imageOriginal (pixmapOriginal.toImage()),
00018 m_rgbBackground (rgbBackground),
00019 m_colorFilterMode (NUM_COLOR_FILTER_MODES),
00020 m_low (-1.0),
00021 m_high (-1.0)
00022 {
00023 m_restartTimer.setSingleShot (false);
00024 connect (&m_restartTimer, SIGNAL (timeout ()), this, SLOT (slotRestartTimeout()));
00025 }
00026
00027 void DlgFilterWorker::slotNewParameters (ColorFilterMode colorFilterMode,
00028 double low,
00029 double high)
00030 {
00031 LOG4CPP_INFO_S ((*mainCat)) << "DlgFilterWorker::slotNewParameters filterMode=" << colorFilterMode
00032 << " low=" << low
00033 << " high=" << high;
00034
00035
00036 DlgFilterCommand command (colorFilterMode,
00037 low,
00038 high);
00039 m_inputCommandQueue.push_back (command);
00040
00041 if (!m_restartTimer.isActive()) {
00042
00043
00044 m_restartTimer.start (NO_DELAY);
00045 }
00046 }
00047
00048 void DlgFilterWorker::slotRestartTimeout ()
00049 {
00050 if (m_inputCommandQueue.count() > 0) {
00051
00052 DlgFilterCommand command = m_inputCommandQueue.last();
00053 m_inputCommandQueue.clear ();
00054
00055
00056 m_colorFilterMode = command.colorFilterMode();
00057 m_low = command.low0To1();
00058 m_high = command.high0To1();
00059
00060 m_xLeft = 0;
00061
00062
00063 m_restartTimer.start (NO_DELAY);
00064
00065 } else if (m_xLeft < m_imageOriginal.width ()) {
00066
00067
00068 int xStop = m_xLeft + COLUMNS_PER_PIECE;
00069 if (xStop >= m_imageOriginal.width()) {
00070 xStop = m_imageOriginal.width();
00071 }
00072
00073
00074
00075
00076
00077
00078 ColorFilter filter;
00079 int processedWidth = xStop - m_xLeft;
00080 QImage imageProcessed (processedWidth,
00081 m_imageOriginal.height(),
00082 QImage::Format_RGB32);
00083 for (int xFrom = m_xLeft, xTo = 0; (xFrom < xStop) && (m_inputCommandQueue.count() == 0); xFrom++, xTo++) {
00084 for (int y = 0; (y < m_imageOriginal.height ()) && (m_inputCommandQueue.count() == 0); y++) {
00085 QColor pixel = m_imageOriginal.pixel (xFrom, y);
00086 bool isOn = false;
00087 if (pixel.rgb() != m_rgbBackground) {
00088
00089 isOn = filter.pixelUnfilteredIsOn (m_colorFilterMode,
00090 pixel,
00091 m_rgbBackground,
00092 m_low,
00093 m_high);
00094 }
00095
00096 imageProcessed.setPixel (xTo, y, (isOn ?
00097 QColor (Qt::black).rgb () :
00098 QColor (Qt::white).rgb ()));
00099 }
00100 }
00101
00102 if (m_inputCommandQueue.count() == 0) {
00103 emit signalTransferPiece (m_xLeft,
00104 imageProcessed);
00105 m_xLeft += processedWidth;
00106 }
00107
00108 if ((xStop < m_imageOriginal.width()) ||
00109 (m_inputCommandQueue.count () > 0)) {
00110
00111
00112 m_restartTimer.start (NO_DELAY);
00113 }
00114 }
00115 }