Shinya Kitaoka 810553
#pragma once
Shinya Kitaoka 810553
Toshihiro Shimizu 890ddd
#ifndef TSCANNER_H
Toshihiro Shimizu 890ddd
#define TSCANNER_H
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "trasterimage.h"
Toshihiro Shimizu 890ddd
#include <set></set>
Campbell Barton d0e335
#include <qstring></qstring>
Toshihiro Shimizu 890ddd
#undef DVAPI
Toshihiro Shimizu 890ddd
#undef DVVAR
Toshihiro Shimizu 890ddd
#ifdef TNZBASE_EXPORTS
Toshihiro Shimizu 890ddd
#define DVAPI DV_EXPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_EXPORT_VAR
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define DVAPI DV_IMPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_IMPORT_VAR
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// forward declaration
Toshihiro Shimizu 890ddd
class TOStream;
Toshihiro Shimizu 890ddd
class TIStream;
Toshihiro Shimizu 890ddd
class TFilePath;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
struct DVAPI TScanParam {
Shinya Kitaoka 120a6e
  TScanParam()
Shinya Kitaoka 120a6e
      : m_supported(false)
Shinya Kitaoka 120a6e
      , m_min(0)
Shinya Kitaoka 120a6e
      , m_max(0)
Shinya Kitaoka 120a6e
      , m_def(0)
Shinya Kitaoka 120a6e
      , m_step(0)
Shinya Kitaoka 120a6e
      , m_value(0) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TScanParam(float _min, float _max, float _def, float _step)
Shinya Kitaoka 120a6e
      : m_supported(true)
Shinya Kitaoka 120a6e
      , m_min(_min)
Shinya Kitaoka 120a6e
      , m_max(_max)
Shinya Kitaoka 120a6e
      , m_def(_def)
Shinya Kitaoka 120a6e
      , m_step(1)
Shinya Kitaoka 120a6e
      , m_value(_def) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool m_supported;
Shinya Kitaoka 120a6e
  float m_min, m_max, m_def, m_step,
Shinya Kitaoka 120a6e
      m_value;  // questi sono float per seguire lo standard TWAIN !
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void update(const TScanParam &model);
Shinya Kitaoka 120a6e
  // assegna min,max,def,step e supported da model a this
Shinya Kitaoka 120a6e
  // mantiene value a patto che sia contenuto nel nuovo range, diversamente ne
Shinya Kitaoka 120a6e
  // fa il crop
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class DVAPI TScannerParameters {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  enum ScanType { None, BW, GR8, RGB24 };
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  // Supported scan types: Black and white, graytones, color
Shinya Kitaoka 120a6e
  bool m_bw, m_gray, m_rgb;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Current scan type
Shinya Kitaoka 120a6e
  ScanType m_scanType;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  std::string m_paperFormat;  // e.g. "A4 paper"
Shinya Kitaoka 120a6e
  TRectD m_scanArea;  // in mm /* TWAIN preferirebbe gli inch, ma uso i mm per
Shinya Kitaoka 120a6e
                      // seguire tnz4.x*/
Shinya Kitaoka 120a6e
  TRectD m_cropBox;   // in mm /* TWAIN preferirebbe gli inch, ma uso i mm per
Shinya Kitaoka 120a6e
                      // seguire tnz4.x*/
Shinya Kitaoka 120a6e
  bool m_isPreview;
Shinya Kitaoka 120a6e
  TDimensionD m_maxPaperSize;  // in mm /* TWAIN preferirebbe gli inch, ma uso i
Shinya Kitaoka 120a6e
                               // mm per seguire tnz4.x*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool m_paperOverflow;  // vale true se la scanArea e' stata tagliata rispetto
Shinya Kitaoka 120a6e
                         // alle dimensioni della carta
Shinya Kitaoka 120a6e
                         // per rispettare la maxPaperSize
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool m_validatedByCurrentScanner;
Shinya Kitaoka 120a6e
  // vale false se bisogna ancora chiamare adaptToCurrentScanner()
Shinya Kitaoka 120a6e
  // l'idea e' di chiamare questo metodo il meno possibile
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TScanParam m_brightness;
Shinya Kitaoka 120a6e
  TScanParam m_contrast;
Shinya Kitaoka 120a6e
  TScanParam m_threshold;
Shinya Kitaoka 120a6e
  TScanParam m_dpi;
Shinya Kitaoka 120a6e
  TScanParam m_paperFeeder;  // value==1.0 => use paper feeder
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  // other useful info ?!
Shinya Kitaoka 120a6e
  std::string m_twainVersion;
Shinya Kitaoka 120a6e
  std::string m_manufacturer;
Shinya Kitaoka 120a6e
  std::string m_prodFamily;
Shinya Kitaoka 120a6e
  std::string m_productName;
Shinya Kitaoka 120a6e
  std::string m_version;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool m_reverseOrder;  // if true then scan levels starting from last frame
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void cropScanArea();  // assicura che scanArea sia dentro maxPaperSize
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TScannerParameters();
Shinya Kitaoka 120a6e
  ~TScannerParameters();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void setSupportedTypes(bool bw, bool gray, bool rgb);
Shinya Kitaoka 120a6e
  bool isSupported(ScanType) const;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void setMaxPaperSize(double maxWidth,
Shinya Kitaoka 120a6e
                       double maxHeight);  // note: possibly update m_scanArea
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  std::string getPaperFormat() const { return m_paperFormat; }
Shinya Kitaoka 120a6e
  void setPaperFormat(std::string paperFormat);
Shinya Kitaoka 120a6e
  // assert(TPaperFormatManager::instance()->isValidFormat(paperFormat));
Shinya Kitaoka 120a6e
  // updates scanArea (cropping with maxPaperSize)
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void updatePaperFormat();
Shinya Kitaoka 120a6e
  // if paperFormat=="" set default paper format; recompute (to be sure!)
Shinya Kitaoka 120a6e
  // scanArea
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool getPaperOverflow() const {
Shinya Kitaoka 120a6e
    return m_paperOverflow;
Shinya Kitaoka 120a6e
  }  // true iff paperSize > maxPaperSize
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TRectD getScanArea() const { return m_scanArea; }
Shinya Kitaoka 120a6e
  void setCropBox(const TRectD &cropBox) { m_cropBox = cropBox * m_scanArea; }
Shinya Kitaoka 120a6e
  TRectD getCropBox() const { return m_cropBox; }
Shinya Kitaoka 120a6e
  void setIsPreview(bool isPreview) { m_isPreview = isPreview; };
Shinya Kitaoka 120a6e
  bool isPreview() const { return m_isPreview; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool isReverseOrder() const { return m_reverseOrder; }
Shinya Kitaoka 120a6e
  void setReverseOrder(bool reverseOrder) { m_reverseOrder = reverseOrder; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool isPaperFeederEnabled() const { return m_paperFeeder.m_value == 1.0; }
Shinya Kitaoka 120a6e
  void enablePaperFeeder(bool on) { m_paperFeeder.m_value = on ? 1.0f : 0.0f; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void setScanType(ScanType scanType);
Shinya Kitaoka 120a6e
  ScanType getScanType() const { return m_scanType; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // se e' stato definito uno scanner aggiorna lo stato (enabled/disabled,
Shinya Kitaoka 120a6e
  // range, etc.)
Shinya Kitaoka 120a6e
  // dei parametri rispetto a quest'ultimo
Shinya Kitaoka 120a6e
  void adaptToCurrentScanner();
Shinya Kitaoka 120a6e
  void adaptToCurrentScannerIfNeeded() {
Shinya Kitaoka 120a6e
    if (!m_validatedByCurrentScanner) adaptToCurrentScanner();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void assign(const TScannerParameters *params);
Shinya Kitaoka 120a6e
  void saveData(TOStream &os) const;
Shinya Kitaoka 120a6e
  void loadData(TIStream &is);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class TScannerListener {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  virtual void onImage(const TRasterImageP &) = 0;
Shinya Kitaoka 120a6e
  virtual void onError()                      = 0;
Shinya Kitaoka 120a6e
  virtual void onNextPaper()                  = 0;
Shinya Kitaoka 120a6e
  virtual void onAutomaticallyNextPaper()     = 0;
Shinya Kitaoka 120a6e
  virtual bool isCanceled()                   = 0;
Shinya Kitaoka 120a6e
  virtual ~TScannerListener() {}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class DVAPI TScanner {
Shinya Kitaoka 120a6e
  std::set<tscannerlistener *=""> m_listeners;</tscannerlistener>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Shinya Kitaoka 120a6e
  TScanParam m_brightness, m_contrast, m_threshold, m_dpi;
Shinya Kitaoka 120a6e
  int m_paperLeft;
Shinya Kitaoka 120a6e
  QString m_scannerName;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TScanner();
Shinya Kitaoka 120a6e
  virtual ~TScanner();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  static bool m_isTwain;  // brutto, brutto :(
Shinya Kitaoka 120a6e
  static TScanner *instance();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  virtual void selectDevice()      = 0;
Shinya Kitaoka 120a6e
  virtual bool isDeviceAvailable() = 0;
Shinya Kitaoka 120a6e
  virtual bool isDeviceSelected() { return false; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  virtual void updateParameters(TScannerParameters ¶meters) = 0;
Shinya Kitaoka 120a6e
  // aggiorna i parametri 'parameters' in funzione del tipo di scanner
Shinya Kitaoka 120a6e
  // selezionato
Shinya Kitaoka 120a6e
  // se possibile non modifica i valori correnti, ma cambia solo quello che non
Shinya Kitaoka 120a6e
  // e' piu' adatto
Shinya Kitaoka 120a6e
  // abilita/disabilita i parametri "opzionali".
Shinya Kitaoka 120a6e
  // n.b. i parametri opzionali che vengono disabilitati mantengono il loro
Shinya Kitaoka 120a6e
  // valore
Shinya Kitaoka 120a6e
  // (cosi' se fai save default settings dopo aver cambiato scanner non ti perdi
Shinya Kitaoka 120a6e
  // i vecchi settaggi)
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  virtual void acquire(const TScannerParameters ¶m, int paperCount) = 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void addListener(TScannerListener *);
Shinya Kitaoka 120a6e
  void removeListener(TScannerListener *);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void notifyImageDone(const TRasterImageP &image);
Shinya Kitaoka 120a6e
  void notifyNextPaper();
Shinya Kitaoka 120a6e
  void notifyAutomaticallyNextPaper();
Shinya Kitaoka 120a6e
  void notifyError();
Shinya Kitaoka 120a6e
  bool isScanningCanceled();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int getPaperLeftCount() const { return m_paperLeft; }
Shinya Kitaoka 120a6e
  void setPaperLeftCount(int count) { m_paperLeft = count; }
Shinya Kitaoka 120a6e
  void decrementPaperLeftCount() { --m_paperLeft; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QString getName() const { return m_scannerName; }
Shinya Kitaoka 120a6e
  void setName(const QString &name) { m_scannerName = name; }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class DVAPI TPaperFormatManager {  // singleton
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  class Format {
Shinya Kitaoka 120a6e
  public:
Shinya Kitaoka 120a6e
    TDimensionD m_size;
Shinya Kitaoka 120a6e
    Format() : m_size(0, 0) {}
Shinya Kitaoka 120a6e
    Format(const TDimensionD &size) : m_size(size) {}
Shinya Kitaoka 120a6e
  };
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  typedef std::map<std::string, format=""> FormatTable;</std::string,>
Shinya Kitaoka 120a6e
  FormatTable m_formats;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TPaperFormatManager();
Shinya Kitaoka 120a6e
  void readPaperFormat(const TFilePath &fp);
Shinya Kitaoka 120a6e
  void readPaperFormats();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  static TPaperFormatManager *instance();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // resitutisce la lista dei formati
Shinya Kitaoka 120a6e
  void getFormats(std::vector<std::string> &names) const;</std::string>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool isValidFormat(std::string name) const;
Shinya Kitaoka 120a6e
  std::string getDefaultFormat() const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // nome formato --> dimensione
Shinya Kitaoka 120a6e
  TDimensionD getSize(std::string name) const;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif