~ubuntu-branches/ubuntu/intrepid/digikam/intrepid

« back to all changes in this revision

Viewing changes to digikam/imageplugins/hotpixels/blackframeparser.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mark Purcell
  • Date: 2008-07-17 20:25:39 UTC
  • mfrom: (1.2.15 upstream) (3.1.2 lenny)
  • Revision ID: james.westby@ubuntu.com-20080717202539-6n7dtirbkoo7qvhd
Tags: 2:0.9.4-1
* New upstream release
  - digiKam 0.9.4 Release Plan (KDE3) ~ 13 July 08 (Closes: #490144)
* DEB_CONFIGURE_EXTRA_FLAGS := --without-included-sqlite3
* Debhelper compatibility level V7
* Install pixmaps in debian/*.install
* Add debian/digikam.lintian-overrides

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
 * Description : black frames parser
8
8
 * 
9
9
 * Copyright (C) 2005-2006 by Unai Garro <ugarro at users dot sourceforge dot net>
 
10
 * Copyright (C) 2005-2008 by Gilles Caulier <caulier dot gilles at gmail dot com>
10
11
 * 
11
12
 * Part of the algorithm for finding the hot pixels was based on
12
13
 * the code of jpegpixi, which was released under the GPL license,
40
41
#include <qimage.h>
41
42
#include <qstringlist.h>
42
43
 
 
44
// KDE includes.
 
45
 
 
46
#include <kapplication.h>
 
47
#include <kdeversion.h>
 
48
#include <kio/netaccess.h>
 
49
#include <kio/job.h>
 
50
 
43
51
// Local includes.
44
52
 
45
53
#include "blackframeparser.h"
48
56
namespace DigikamHotPixelsImagesPlugin
49
57
{
50
58
 
51
 
BlackFrameParser::BlackFrameParser()
52
 
                : QObject()
 
59
BlackFrameParser::BlackFrameParser(QObject *parent)
 
60
                : QObject(parent)
53
61
{
 
62
    m_imageLoaderThread = 0;
54
63
}
55
64
 
56
65
BlackFrameParser::~BlackFrameParser()
57
66
{
58
 
}
59
 
 
60
 
void BlackFrameParser::parseHotPixels(QString file)
61
 
{
62
 
    parseBlackFrame(file);
63
 
    
64
 
    /*
65
 
    mOutputString ="";
66
 
    
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)));
72
 
    *proc << "jpeghotp";
73
 
    *proc << file;
74
 
    proc->start( KProcess::NotifyOnExit, KProcess::Stdout);    
75
 
    */
76
 
}
77
 
 
78
 
void BlackFrameParser::parseBlackFrame(KURL url)
79
 
{
80
 
    //Initialize the data buffer
81
 
    mData.resize(0);
82
 
 
83
 
    //And open the file
84
 
    
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& )));
88
 
    
89
 
    connect(job, SIGNAL(result(KIO::Job* )), 
90
 
            this, SLOT(slotResult(KIO::Job*)));
 
67
    delete m_imageLoaderThread;
 
68
}
 
69
 
 
70
void BlackFrameParser::parseHotPixels(const QString &file)
 
71
{
 
72
    parseBlackFrame(KURL(file));
 
73
}
 
74
 
 
75
void BlackFrameParser::parseBlackFrame(const KURL &url)
 
76
{
 
77
#if KDE_IS_VERSION(3,2,0)
 
78
    KIO::NetAccess::download(url, m_localFile, kapp->activeWindow());
 
79
#else
 
80
    KIO::NetAccess::download(url, m_localFile);
 
81
#endif
 
82
 
 
83
    if (!m_imageLoaderThread)
 
84
    {
 
85
        m_imageLoaderThread = new LoadSaveThread();
 
86
 
 
87
        connect(m_imageLoaderThread, SIGNAL(signalLoadingProgress(const LoadingDescription&, float)),
 
88
                this, SLOT(slotLoadingProgress(const LoadingDescription&, float)));
 
89
 
 
90
        connect(m_imageLoaderThread, SIGNAL(signalImageLoaded(const LoadingDescription&, const DImg&)),
 
91
                this, SLOT(slotLoadImageFromUrlComplete(const LoadingDescription&, const DImg&)));
 
92
    }
 
93
 
 
94
    LoadingDescription desc = LoadingDescription(m_localFile, KDcrawIface::RawDecodingSettings());
 
95
    m_imageLoaderThread->load(desc);
 
96
}
 
97
 
 
98
void BlackFrameParser::slotLoadingProgress(const LoadingDescription&, float v)
 
99
{
 
100
    emit signalLoadingProgress(v);
 
101
}
 
102
 
 
103
void BlackFrameParser::slotLoadImageFromUrlComplete(const LoadingDescription&, const DImg& img)
 
104
{
 
105
    DImg image(img);
 
106
    m_Image = image.copyQImage();
 
107
    blackFrameParsing();
 
108
    emit signalLoadingComplete();
91
109
}
92
110
 
93
111
void BlackFrameParser::parseBlackFrame(QImage& img)
94
112
{
95
 
    mImage=img;
 
113
    m_Image = img;
96
114
    blackFrameParsing();
97
115
}
98
116
 
99
 
void BlackFrameParser::blackFrameDataArrived(KIO::Job*,const QByteArray& data)
100
 
{
101
 
    uint size=mData.size();
102
 
    uint dataSize=data.size();
103
 
    mData.resize(size+dataSize);
104
 
    memcpy(mData.data()+size,data.data(),dataSize);
105
 
}
106
 
 
107
 
void BlackFrameParser::slotResult(KIO::Job*)
108
 
{
109
 
    blackFrameParsing(true);
110
 
}
111
 
 
112
117
// Parses black frames
113
118
 
114
 
void BlackFrameParser::blackFrameParsing(bool useData)
 
119
void BlackFrameParser::blackFrameParsing()
115
120
{
116
 
    //First we create a QImage out of the file data if we are using it
117
 
    if (useData) 
118
 
    {
119
 
        mImage.loadFromData(mData);
120
 
    }
121
121
    // Now find the hot pixels and store them in a list
122
122
    QValueList<HotPixel> hpList;
123
 
    
124
 
    for (int y=0 ; y < mImage.height() ; ++y)
 
123
 
 
124
    for (int y=0 ; y < m_Image.height() ; ++y)
125
125
    {
126
 
        for (int x=0 ; x < mImage.width() ; ++x)
 
126
        for (int x=0 ; x < m_Image.width() ; ++x)
127
127
        {
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);
131
 
            
 
131
 
132
132
            // Find maximum component value.
133
133
            int maxValue;
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();
138
138
 
139
139
            // If the component is bigger than the threshold, add the point
140
140
            if (maxValue > threshold_value)
141
141
            {
142
142
                HotPixel point;
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;
146
 
    
 
146
 
147
147
                hpList.append(point);
148
148
            }
149
149
        }
150
150
    }
151
 
    
 
151
 
152
152
    //Now join points together into groups
153
153
    consolidatePixels (hpList);
154
 
    
 
154
 
155
155
    //And notify
156
156
    emit parsed(hpList);
157
157
}
164
164
        return;
165
165
 
166
166
    /* Consolidate horizontally.  */
167
 
    
 
167
 
168
168
    QValueList<HotPixel>::iterator it, prevPointIt;
169
169
 
170
 
    prevPointIt=list.begin();
171
 
    it=list.begin();
 
170
    prevPointIt = list.begin();
 
171
    it          = list.begin();
172
172
    ++it;
173
 
    
 
173
 
174
174
    HotPixel tmp;
175
175
    HotPixel point;
176
176
    HotPixel point_below;
181
181
        {
182
182
            point = (*it);
183
183
            tmp   = point;
184
 
    
 
184
 
185
185
            QValueList<HotPixel>::Iterator point_below_it;
186
186
            point_below_it = list.find (tmp); //find any intersecting hotp below tmp
187
187
            if (point_below_it != list.end())
188
188
            {
189
189
                point_below =* point_below_it;
190
190
                validateAndConsolidate (&point, &point_below);
191
 
                
 
191
 
192
192
                point.rect.setX(MIN(point.x(), point_below.x()));
193
193
                point.rect.setWidth(MAX(point.x() + point.width(),
194
194
                                    point_below.x() + point_below.width()) - point.x());
195
195
                point.rect.setHeight(MAX(point.y() + point.height(),
196
196
                                     point_below.y() + point_below.height()) - point.y());
197
 
                *it=point;
 
197
                *it = point;
198
198
                list.remove (point_below_it); //TODO: Check! this could remove it++?
199
199
            }
200
 
            else    
 
200
            else
201
201
                break;
202
202
        }
203
203
    }