Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef TIMAGE_IO_INCLUDED
Toshihiro Shimizu 890ddd
#define TIMAGE_IO_INCLUDED
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//#include "trasterimage.h"
Toshihiro Shimizu 890ddd
//#include "texception.h"
Toshihiro Shimizu 890ddd
//#include "tfilepath.h"
Toshihiro Shimizu 890ddd
#include <qstringlist></qstringlist>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tfilepath_io.h"
Toshihiro Shimizu 890ddd
#include "traster.h"
Toshihiro Shimizu 890ddd
#include "timage.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#undef DVAPI
Toshihiro Shimizu 890ddd
#undef DVVAR
Toshihiro Shimizu 890ddd
#ifdef TIMAGE_IO_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
Shinya Kitaoka 120a6e
namespace Tiio {
Toshihiro Shimizu 890ddd
class Reader;
Toshihiro Shimizu 890ddd
class Writer;
Toshihiro Shimizu 890ddd
class VectorReader;
Toshihiro Shimizu 890ddd
class VectorWriter;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
class TPropertyGroup;
Toshihiro Shimizu 890ddd
class TImageInfo;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===========================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class DVAPI TImageException : public TException {
Shinya Kitaoka 120a6e
  TFilePath m_fp;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TImageException(const TFilePath &fp, const std::string &msg);
Shinya Kitaoka 120a6e
  ~TImageException() {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  TString getMessage() const override;
Shinya Kitaoka 120a6e
  TString getRawMessage() const { return TException::getMessage(); }
Shinya Kitaoka 120a6e
  const TFilePath &getFilePath() const { return m_fp; }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===========================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class DVAPI TImageVersionException : public TException {
Shinya Kitaoka 120a6e
  TFilePath m_fp;
Shinya Kitaoka 120a6e
  int m_major, m_minor;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TImageVersionException(const TFilePath &fp, int major, int minor);
Shinya Kitaoka 120a6e
  ~TImageVersionException() {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void getVersion(int &major, int &minor) const {
Shinya Kitaoka 120a6e
    major = m_major;
Shinya Kitaoka 120a6e
    minor = m_minor;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  int getMajor() const { return m_major; }
Shinya Kitaoka 120a6e
  int getMinor() const { return m_minor; }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===========================================================
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// Image Reader
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//===========================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class TImageReader;
Toshihiro Shimizu 890ddd
typedef TImageReader *TImageReaderCreateProc(const TFilePath &path);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===========================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//! \include imgReader_ex.cpp
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class DVAPI TImageReader : public TSmartObject {
Shinya Kitaoka 120a6e
  DECLARE_CLASS_CODE
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  friend class TImageReaderP;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Shinya Kitaoka 120a6e
  // std::fstream m_stream;
Shinya Kitaoka 120a6e
  TFilePath m_path;
Shinya Kitaoka 120a6e
  FILE *m_file;
Shinya Kitaoka 120a6e
  Tiio::Reader *m_reader;
Shinya Kitaoka 120a6e
  Tiio::VectorReader *m_vectorReader;
Shinya Kitaoka 120a6e
  void open();
Shinya Kitaoka 120a6e
  void close();
Shinya Kitaoka 120a6e
  bool isOpen() const;
Shinya Kitaoka 120a6e
  bool m_readGreytones;
Shinya Kitaoka 120a6e
  bool m_is64BitEnabled;
Shinya Kitaoka 120a6e
  int m_shrink;
Shinya Kitaoka 120a6e
  TRect m_region;
Shinya Kitaoka 120a6e
  static bool m_safeMode;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  static void setSafeModeReadingForTzl(bool activated) {
Shinya Kitaoka 120a6e
    m_safeMode = activated;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  TImageReader(const TFilePath &path);
Shinya Kitaoka 120a6e
  virtual ~TImageReader();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  // not implemented
Shinya Kitaoka 120a6e
  TImageReader(const TImageReader &);
Shinya Kitaoka 120a6e
  TImageReader &operator=(const TImageReader &src);
Shinya Kitaoka 120a6e
  TImageP load0();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  // TImageReader keeps ownership: DO NOT DELETE
Shinya Kitaoka 120a6e
  virtual const TImageInfo *getImageInfo() const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TFilePath getFilePath() const { return m_path; };
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TPropertyGroup *getProperties();
Shinya Kitaoka 120a6e
  void setProperties(const TPropertyGroup *);
Shinya Kitaoka 120a6e
  /*! Load Image from disk.
Shinya Kitaoka 120a6e
If set region then loads only image's region.
Shinya Kitaoka 120a6e
          If set shrink then loads image (or region, if set) with shrink.
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
Note: if the region, or part of it, is not contained in the image
Shinya Kitaoka 120a6e
    then returns only the intersection between the image and region.
Shinya Kitaoka 120a6e
          If the intersection is void returns TImageP();
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
  virtual TImageP load();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void load(const TRasterP &ras, const TPoint &pos = TPoint(0, 0),
Shinya Kitaoka 120a6e
            int shrinkX = 1, int shrinkY = 1);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  static bool load(const TFilePath &, TRasterP &);
Shinya Kitaoka 120a6e
  static bool load(const TFilePath &, TImageP &);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Only for TLV (version 13). Return the icon in TLV file.
Shinya Kitaoka 120a6e
  virtual TImageP loadIcon() { return TImageP(); }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  static void getSupportedFormats(QStringList &names);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // TDimension getSize() const;
Shinya Kitaoka 120a6e
  // virtual TRect getBBox() const = 0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  static void define(QString extension, TImageReaderCreateProc *proc);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void doReadGraytones(bool readThem);
Shinya Kitaoka 120a6e
  void enable16BitRead(bool is64bitEnabled) {
Shinya Kitaoka 120a6e
    m_is64BitEnabled = is64bitEnabled;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int getShrink() const { return m_shrink; }
Shinya Kitaoka 120a6e
  /*!
Shinya Kitaoka 120a6e
     Setta lo shrink in modo che al load() viene letta da disco
Shinya Kitaoka 120a6e
           una riga ogni "shrink" righe ed all'interno di queste righe viene
Shinya Kitaoka 120a6e
     letto un pixel ogni "shrink" pixel.
Shinya Kitaoka 120a6e
           La prima riga viene sempre letta.
Shinya Kitaoka 120a6e
           Il primo pixel di una riga letta viene sempre preso.
Shinya Kitaoka 120a6e
     Nota che se shrink=1 non viene saltata alcuna riga ne pixel.
Shinya Kitaoka 120a6e
  */
Shinya Kitaoka 120a6e
  void setShrink(int shrink);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  /*!
Shinya Kitaoka 120a6e
Set image's region.
Shinya Kitaoka 120a6e
Region dimension doesn't consider shrink.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
  void setRegion(TRect rect) { m_region = rect; }
Shinya Kitaoka 120a6e
  /*!
Shinya Kitaoka 120a6e
Returns the image region.
Shinya Kitaoka 120a6e
Region dimension doesn't consider shrink
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
  TRect getRegion() const { return m_region; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void getTzpPaletteColorNames(
Shinya Kitaoka 120a6e
      std::map<int, std::pair<std::string,="" std::string="">></int,>
Shinya Kitaoka 120a6e
          &pltColorNames);  // colorindex(<256: paint), pagename, colorname
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Toshihiro Shimizu 890ddd
template class DVAPI TSmartPointerT<timagereader>;</timagereader>
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class DVAPI TImageReaderP : public TSmartPointerT<timagereader> {</timagereader>
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TImageReaderP(TImageReader *ir) : TSmartPointerT<timagereader>(ir){};</timagereader>
Shinya Kitaoka 120a6e
  // il costruttore "non banale"
Shinya Kitaoka 120a6e
  TImageReaderP(const TFilePath &filepath);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===========================================================
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// Image Writer
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//===========================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class TImageWriter;
Toshihiro Shimizu 890ddd
typedef TImageWriter *TImageWriterCreateProc(const TFilePath &path);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===========================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//! \include imgWriter_ex.cpp
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class DVAPI TImageWriter : public TSmartObject {
Shinya Kitaoka 120a6e
  DECLARE_CLASS_CODE
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Shinya Kitaoka 120a6e
  // std::fstream m_stream;
Shinya Kitaoka 120a6e
  TFilePath m_path;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  Tiio::Writer *m_writer;
Shinya Kitaoka 120a6e
  Tiio::VectorWriter *m_vectorWriter;
Shinya Kitaoka 120a6e
  TPropertyGroup *m_properties;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TImageWriter(const TFilePath &path);
Shinya Kitaoka 120a6e
  virtual ~TImageWriter();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  // not implemented
Shinya Kitaoka 120a6e
  TImageWriter(const TImageWriter &);
Shinya Kitaoka 120a6e
  TImageWriter &operator=(const TImageWriter &src);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TFilePath getFilePath() const { return m_path; };
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // don't get ownership
Shinya Kitaoka 120a6e
  void setProperties(const TPropertyGroup *);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  virtual void save(const TImageP &img);
Shinya Kitaoka 120a6e
  virtual bool is64bitOutputSupported() { return true; }
Shinya Kitaoka 120a6e
  static void save(const TFilePath &, TRasterP);
Shinya Kitaoka 120a6e
  static void save(const TFilePath &, const TImageP &);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  static void getSupportedFormats(QStringList &names, bool onlyRenderFormats);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  static void define(QString extension, TImageWriterCreateProc *proc,
Shinya Kitaoka 120a6e
                     bool isRenderFormat);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Toshihiro Shimizu 890ddd
template class DVAPI TSmartPointerT<timagewriter>;</timagewriter>
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class DVAPI TImageWriterP : public TSmartPointerT<timagewriter> {</timagewriter>
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TImageWriterP(TImageWriter *iw) : TSmartPointerT<timagewriter>(iw){};</timagewriter>
Shinya Kitaoka 120a6e
  // il costruttore "non banale"
Shinya Kitaoka 120a6e
  TImageWriterP(const TFilePath &filepath);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===========================================================
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// Image ReaderWriter
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//===========================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class TImageReaderWriter;
Toshihiro Shimizu 890ddd
typedef TImageReaderWriter *TImageReaderWriterCreateProc(const TFilePath &path);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===========================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif