48
56
namespace DigikamHotPixelsImagesPlugin
51
BlackFrameParser::BlackFrameParser()
59
BlackFrameParser::BlackFrameParser(QObject *parent)
62
m_imageLoaderThread = 0;
56
65
BlackFrameParser::~BlackFrameParser()
60
void BlackFrameParser::parseHotPixels(QString file)
62
parseBlackFrame(file);
67
//First, lets run jpeghotp on the blackframe file
68
KProcess *proc = new KProcess;
69
connect(proc, SIGNAL(processExited(KProcess*)),this, SLOT(processed(KProcess*)));
70
connect(proc, SIGNAL(receivedStdout(KProcess*, char*,int)),this,SLOT(HotPData(KProcess*, char*,int)));
71
connect(proc, SIGNAL(receivedStderr(KProcess*, char*,int)),this,SLOT(HotPData(KProcess*, char*,int)));
74
proc->start( KProcess::NotifyOnExit, KProcess::Stdout);
78
void BlackFrameParser::parseBlackFrame(KURL url)
80
//Initialize the data buffer
85
KIO::TransferJob *job = KIO::get(url, false, false);
86
connect(job, SIGNAL(data( KIO::Job*, const QByteArray&)),
87
this, SLOT( blackFrameDataArrived( KIO::Job *, const QByteArray& )));
89
connect(job, SIGNAL(result(KIO::Job* )),
90
this, SLOT(slotResult(KIO::Job*)));
67
delete m_imageLoaderThread;
70
void BlackFrameParser::parseHotPixels(const QString &file)
72
parseBlackFrame(KURL(file));
75
void BlackFrameParser::parseBlackFrame(const KURL &url)
77
#if KDE_IS_VERSION(3,2,0)
78
KIO::NetAccess::download(url, m_localFile, kapp->activeWindow());
80
KIO::NetAccess::download(url, m_localFile);
83
if (!m_imageLoaderThread)
85
m_imageLoaderThread = new LoadSaveThread();
87
connect(m_imageLoaderThread, SIGNAL(signalLoadingProgress(const LoadingDescription&, float)),
88
this, SLOT(slotLoadingProgress(const LoadingDescription&, float)));
90
connect(m_imageLoaderThread, SIGNAL(signalImageLoaded(const LoadingDescription&, const DImg&)),
91
this, SLOT(slotLoadImageFromUrlComplete(const LoadingDescription&, const DImg&)));
94
LoadingDescription desc = LoadingDescription(m_localFile, KDcrawIface::RawDecodingSettings());
95
m_imageLoaderThread->load(desc);
98
void BlackFrameParser::slotLoadingProgress(const LoadingDescription&, float v)
100
emit signalLoadingProgress(v);
103
void BlackFrameParser::slotLoadImageFromUrlComplete(const LoadingDescription&, const DImg& img)
106
m_Image = image.copyQImage();
108
emit signalLoadingComplete();
93
111
void BlackFrameParser::parseBlackFrame(QImage& img)
96
114
blackFrameParsing();
99
void BlackFrameParser::blackFrameDataArrived(KIO::Job*,const QByteArray& data)
101
uint size=mData.size();
102
uint dataSize=data.size();
103
mData.resize(size+dataSize);
104
memcpy(mData.data()+size,data.data(),dataSize);
107
void BlackFrameParser::slotResult(KIO::Job*)
109
blackFrameParsing(true);
112
117
// Parses black frames
114
void BlackFrameParser::blackFrameParsing(bool useData)
119
void BlackFrameParser::blackFrameParsing()
116
//First we create a QImage out of the file data if we are using it
119
mImage.loadFromData(mData);
121
121
// Now find the hot pixels and store them in a list
122
122
QValueList<HotPixel> hpList;
124
for (int y=0 ; y < mImage.height() ; ++y)
124
for (int y=0 ; y < m_Image.height() ; ++y)
126
for (int x=0 ; x < mImage.width() ; ++x)
126
for (int x=0 ; x < m_Image.width() ; ++x)
128
128
//Get each point in the image
129
QRgb pixrgb=mImage.pixel(x,y);
129
QRgb pixrgb = m_Image.pixel(x,y);
130
130
QColor color; color.setRgb(pixrgb);
132
132
// Find maximum component value.
134
int threshold=DENOM/10;
135
const int threshold_value = REL_TO_ABS(threshold,255);
136
maxValue=(color.red()>color.blue()) ? color.red() : color.blue();
137
if (color.green()>maxValue) maxValue=color.green();
134
int threshold = DENOM/10;
135
const int threshold_value = REL_TO_ABS(threshold, 255);
136
maxValue = (color.red()>color.blue()) ? color.red() : color.blue();
137
if (color.green() > maxValue) maxValue = color.green();
139
139
// If the component is bigger than the threshold, add the point
140
140
if (maxValue > threshold_value)
143
point.rect=QRect (x,y,1,1);
143
point.rect = QRect (x, y, 1, 1);
144
144
//TODO:check this
145
145
point.luminosity = ((2 * DENOM) / 255 ) * maxValue / 2;
147
147
hpList.append(point);
152
152
//Now join points together into groups
153
153
consolidatePixels (hpList);
156
156
emit parsed(hpList);