| #pragma once |
| |
| #ifndef TSCANNER_H |
| #define TSCANNER_H |
| |
| #include "trasterimage.h" |
| #include <set> |
| #include <QString> |
| #undef DVAPI |
| #undef DVVAR |
| #ifdef TNZBASE_EXPORTS |
| #define DVAPI DV_EXPORT_API |
| #define DVVAR DV_EXPORT_VAR |
| #else |
| #define DVAPI DV_IMPORT_API |
| #define DVVAR DV_IMPORT_VAR |
| #endif |
| |
| |
| class TOStream; |
| class TIStream; |
| class TFilePath; |
| |
| struct DVAPI TScanParam { |
| TScanParam() |
| : m_supported(false) |
| , m_min(0) |
| , m_max(0) |
| , m_def(0) |
| , m_step(0) |
| , m_value(0) {} |
| |
| TScanParam(float _min, float _max, float _def, float _step) |
| : m_supported(true) |
| , m_min(_min) |
| , m_max(_max) |
| , m_def(_def) |
| , m_step(1) |
| , m_value(_def) {} |
| |
| bool m_supported; |
| float m_min, m_max, m_def, m_step, |
| m_value; |
| |
| void update(const TScanParam &model); |
| |
| |
| |
| }; |
| |
| class DVAPI TScannerParameters { |
| public: |
| enum ScanType { None, BW, GR8, RGB24 }; |
| |
| private: |
| |
| bool m_bw, m_gray, m_rgb; |
| |
| |
| ScanType m_scanType; |
| |
| std::string m_paperFormat; |
| TRectD m_scanArea; |
| |
| TRectD m_cropBox; |
| |
| bool m_isPreview; |
| TDimensionD m_maxPaperSize; |
| |
| |
| bool m_paperOverflow; |
| |
| |
| |
| bool m_validatedByCurrentScanner; |
| |
| |
| |
| public: |
| TScanParam m_brightness; |
| TScanParam m_contrast; |
| TScanParam m_threshold; |
| TScanParam m_dpi; |
| TScanParam m_paperFeeder; |
| |
| private: |
| |
| std::string m_twainVersion; |
| std::string m_manufacturer; |
| std::string m_prodFamily; |
| std::string m_productName; |
| std::string m_version; |
| |
| bool m_reverseOrder; |
| |
| void cropScanArea(); |
| |
| public: |
| TScannerParameters(); |
| ~TScannerParameters(); |
| |
| void setSupportedTypes(bool bw, bool gray, bool rgb); |
| bool isSupported(ScanType) const; |
| |
| void setMaxPaperSize(double maxWidth, |
| double maxHeight); |
| |
| std::string getPaperFormat() const { return m_paperFormat; } |
| void setPaperFormat(std::string paperFormat); |
| |
| |
| |
| void updatePaperFormat(); |
| |
| |
| |
| bool getPaperOverflow() const { |
| return m_paperOverflow; |
| } |
| |
| TRectD getScanArea() const { return m_scanArea; } |
| void setCropBox(const TRectD &cropBox) { m_cropBox = cropBox * m_scanArea; } |
| TRectD getCropBox() const { return m_cropBox; } |
| void setIsPreview(bool isPreview) { m_isPreview = isPreview; }; |
| bool isPreview() const { return m_isPreview; } |
| |
| bool isReverseOrder() const { return m_reverseOrder; } |
| void setReverseOrder(bool reverseOrder) { m_reverseOrder = reverseOrder; } |
| |
| bool isPaperFeederEnabled() const { return m_paperFeeder.m_value == 1.0; } |
| void enablePaperFeeder(bool on) { m_paperFeeder.m_value = on ? 1.0f : 0.0f; } |
| |
| void setScanType(ScanType scanType); |
| ScanType getScanType() const { return m_scanType; } |
| |
| |
| |
| |
| void adaptToCurrentScanner(); |
| void adaptToCurrentScannerIfNeeded() { |
| if (!m_validatedByCurrentScanner) adaptToCurrentScanner(); |
| } |
| |
| void assign(const TScannerParameters *params); |
| void saveData(TOStream &os) const; |
| void loadData(TIStream &is); |
| }; |
| |
| |
| |
| class TScannerListener { |
| public: |
| virtual void onImage(const TRasterImageP &) = 0; |
| virtual void onError() = 0; |
| virtual void onNextPaper() = 0; |
| virtual void onAutomaticallyNextPaper() = 0; |
| virtual bool isCanceled() = 0; |
| virtual ~TScannerListener() {} |
| }; |
| |
| |
| |
| class DVAPI TScanner { |
| std::set<TScannerListener *> m_listeners; |
| |
| protected: |
| TScanParam m_brightness, m_contrast, m_threshold, m_dpi; |
| int m_paperLeft; |
| QString m_scannerName; |
| |
| public: |
| TScanner(); |
| virtual ~TScanner(); |
| |
| static bool m_isTwain; |
| static TScanner *instance(); |
| |
| virtual void selectDevice() = 0; |
| virtual bool isDeviceAvailable() = 0; |
| virtual bool isDeviceSelected() { return false; } |
| |
| virtual void updateParameters(TScannerParameters ¶meters) = 0; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| virtual void acquire(const TScannerParameters ¶m, int paperCount) = 0; |
| |
| void addListener(TScannerListener *); |
| void removeListener(TScannerListener *); |
| |
| void notifyImageDone(const TRasterImageP &image); |
| void notifyNextPaper(); |
| void notifyAutomaticallyNextPaper(); |
| void notifyError(); |
| bool isScanningCanceled(); |
| |
| int getPaperLeftCount() const { return m_paperLeft; } |
| void setPaperLeftCount(int count) { m_paperLeft = count; } |
| void decrementPaperLeftCount() { --m_paperLeft; } |
| |
| QString getName() const { return m_scannerName; } |
| void setName(const QString &name) { m_scannerName = name; } |
| }; |
| |
| |
| |
| class DVAPI TPaperFormatManager { |
| public: |
| class Format { |
| public: |
| TDimensionD m_size; |
| Format() : m_size(0, 0) {} |
| Format(const TDimensionD &size) : m_size(size) {} |
| }; |
| |
| private: |
| typedef std::map<std::string, Format> FormatTable; |
| FormatTable m_formats; |
| |
| TPaperFormatManager(); |
| void readPaperFormat(const TFilePath &fp); |
| void readPaperFormats(); |
| |
| public: |
| static TPaperFormatManager *instance(); |
| |
| |
| void getFormats(std::vector<std::string> &names) const; |
| |
| bool isValidFormat(std::string name) const; |
| std::string getDefaultFormat() const; |
| |
| |
| TDimensionD getSize(std::string name) const; |
| }; |
| |
| #endif |