dfmanager cleanup (#6211)

* Turn `DFManager` into a singleton
* PIMPL `DFManager`
* Cleanup namespace usage in `dfmanager.cc`
* Constify `DFManager` interface
* Fix bad `reinterpret_cast` between `std::string` and `Glib::ustring`

Co-authored-by: Flössie <floessie.mail@gmail.com>
Co-authored-by: Thanatomanic <6567747+Thanatomanic@users.noreply.github.com>
This commit is contained in:
Ingo Weyrich
2022-08-18 17:00:49 +02:00
committed by GitHub
parent d8320bc8b7
commit f564394bbc
11 changed files with 439 additions and 391 deletions

View File

@@ -18,89 +18,40 @@
*/
#pragma once
#include <cmath>
#include <list>
#include <map>
#include <memory>
#include <string>
#include <vector>
#include <glibmm/ustring.h>
#include "pixelsmap.h"
namespace rtengine
{
struct badPix;
class RawImage;
class dfInfo final
{
public:
Glib::ustring pathname; // filename of dark frame
std::list<Glib::ustring> pathNames; // other similar dark frames, used for average
std::string maker; ///< manufacturer
std::string model; ///< model
int iso; ///< ISO (gain)
double shutter; ///< shutter or exposure time in sec
time_t timestamp; ///< seconds since 1 Jan 1970
dfInfo(const Glib::ustring &name, const std::string &mak, const std::string &mod, int iso, double shut, time_t t)
: pathname(name), maker(mak), model(mod), iso(iso), shutter(shut), timestamp(t), ri(nullptr) {}
dfInfo( const dfInfo &o)
: pathname(o.pathname), maker(o.maker), model(o.model), iso(o.iso), shutter(o.shutter), timestamp(o.timestamp), ri(nullptr) {}
~dfInfo();
dfInfo &operator =(const dfInfo &o);
bool operator <(const dfInfo &e2) const;
// Calculate virtual distance between two shots; different model return infinite
double distance(const std::string &mak, const std::string &mod, int iso, double shutter) const;
static std::string key(const std::string &mak, const std::string &mod, int iso, double shut );
std::string key()
{
return key( maker, model, iso, shutter);
}
RawImage *getRawImage();
std::vector<badPix> &getHotPixels();
protected:
RawImage *ri; ///< Dark Frame raw data
std::vector<badPix> badPixels; ///< Extracted hot pixels
void updateBadPixelList( RawImage *df );
void updateRawImage();
};
class DFManager final
{
public:
void init(const Glib::ustring &pathname);
Glib::ustring getPathname()
{
return currentPath;
};
void getStat( int &totFiles, int &totTemplate);
RawImage *searchDarkFrame( const std::string &mak, const std::string &mod, int iso, double shut, time_t t );
RawImage *searchDarkFrame( const Glib::ustring filename );
std::vector<badPix> *getHotPixels ( const std::string &mak, const std::string &mod, int iso, double shut, time_t t );
std::vector<badPix> *getHotPixels ( const Glib::ustring filename );
std::vector<badPix> *getBadPixels ( const std::string &mak, const std::string &mod, const std::string &serial);
static DFManager& getInstance();
protected:
typedef std::multimap<std::string, dfInfo> dfList_t;
typedef std::map<std::string, std::vector<badPix> > bpList_t;
dfList_t dfList;
bpList_t bpList;
bool initialized;
Glib::ustring currentPath;
dfInfo *addFileInfo(const Glib::ustring &filename, bool pool = true );
dfInfo *find( const std::string &mak, const std::string &mod, int isospeed, double shut, time_t t );
int scanBadPixelsFile( Glib::ustring filename );
void init(const Glib::ustring& pathname);
Glib::ustring getPathname() const;
void getStat(int& totFiles, int& totTemplates) const;
const RawImage* searchDarkFrame(const std::string& mak, const std::string& mod, int iso, double shut, time_t t);
const RawImage* searchDarkFrame(const Glib::ustring& filename);
const std::vector<badPix>* getHotPixels(const std::string& mak, const std::string& mod, int iso, double shut, time_t t);
const std::vector<badPix>* getHotPixels(const Glib::ustring& filename);
const std::vector<badPix>* getBadPixels(const std::string& mak, const std::string& mod, const std::string& serial) const;
private:
DFManager();
~DFManager();
class Implementation;
const std::unique_ptr<Implementation> implementation;
};
extern DFManager dfm;
}