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