|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tiio.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tiio.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tiio_jpg.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tproperty.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include <map></map>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------
|
|
Toshihiro Shimizu |
890ddd |
#include <fcntl.h></fcntl.h>
|
|
Toshihiro Shimizu |
890ddd |
#include <sys types.h=""></sys>
|
|
Toshihiro Shimizu |
890ddd |
#include <sys stat.h=""></sys>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
9f5a1b |
#ifdef _WIN32
|
|
Toshihiro Shimizu |
890ddd |
#pragma warning(disable : 4786)
|
|
Toshihiro Shimizu |
890ddd |
#include <io.h></io.h>
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include <stdio.h></stdio.h>
|
|
Toshihiro Shimizu |
890ddd |
//--------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
namespace
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class TiioTable
|
|
Toshihiro Shimizu |
890ddd |
{ // singleton
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
typedef std::map<std::string, *="" tiio::readermaker=""></std::string,>
|
|
Toshihiro Shimizu |
890ddd |
ReaderTable;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
typedef std::map<std::string, *,="" bool="" std::pair<tiio::writermaker="">></std::string,>
|
|
Toshihiro Shimizu |
890ddd |
WriterTable;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
typedef std::map<std::string, *="" tiio::vectorreadermaker=""></std::string,>
|
|
Toshihiro Shimizu |
890ddd |
VectorReaderTable;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
typedef std::map<std::string, *,="" bool="" std::pair<tiio::vectorwritermaker="">></std::string,>
|
|
Toshihiro Shimizu |
890ddd |
VectorWriterTable;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
typedef std::map<std::string, *="" tpropertygroup=""></std::string,>
|
|
Toshihiro Shimizu |
890ddd |
PropertiesTable;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
ReaderTable m_readers;
|
|
Toshihiro Shimizu |
890ddd |
WriterTable m_writers;
|
|
Toshihiro Shimizu |
890ddd |
VectorReaderTable m_vectorReaders;
|
|
Toshihiro Shimizu |
890ddd |
VectorWriterTable m_vectorWriters;
|
|
Toshihiro Shimizu |
890ddd |
PropertiesTable m_writerProperties;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TiioTable() { initialize(); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
static TiioTable *instance()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
static TiioTable theTable;
|
|
Toshihiro Shimizu |
890ddd |
return &theTable;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
~TiioTable()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
for (PropertiesTable::iterator it = m_writerProperties.begin();
|
|
Toshihiro Shimizu |
890ddd |
it != m_writerProperties.end(); ++it)
|
|
Toshihiro Shimizu |
890ddd |
delete it->second;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void add(std::string ext, Tiio::ReaderMaker *fn)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_readers[ext] = fn;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
void add(std::string ext, Tiio::WriterMaker *fn, bool isRenderFormat)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_writers[ext] = std::pair<tiio::writermaker *,="" bool="">(fn, isRenderFormat);</tiio::writermaker>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
void add(std::string ext, Tiio::VectorReaderMaker *fn)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_vectorReaders[ext] = fn;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
void add(std::string ext, Tiio::VectorWriterMaker *fn, bool isRenderFormat)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_vectorWriters[ext] = std::pair<tiio::vectorwritermaker *,="" bool="">(fn, isRenderFormat);</tiio::vectorwritermaker>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
void addWriterProperties(std::string ext, TPropertyGroup *prop)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_writerProperties[ext] = prop;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Tiio::ReaderMaker *findReader(std::string ext) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
ReaderTable::const_iterator it = m_readers.find(ext);
|
|
Toshihiro Shimizu |
890ddd |
if (it == m_readers.end())
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
return it->second;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
Tiio::WriterMaker *findWriter(std::string ext) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
WriterTable::const_iterator it = m_writers.find(ext);
|
|
Toshihiro Shimizu |
890ddd |
if (it == m_writers.end())
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
return it->second.first;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
Tiio::VectorReaderMaker *findVectorReader(std::string ext) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
VectorReaderTable::const_iterator it = m_vectorReaders.find(ext);
|
|
Toshihiro Shimizu |
890ddd |
if (it == m_vectorReaders.end())
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
return it->second;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
Tiio::VectorWriterMaker *findVectorWriter(std::string ext) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
VectorWriterTable::const_iterator it = m_vectorWriters.find(ext);
|
|
Toshihiro Shimizu |
890ddd |
if (it == m_vectorWriters.end())
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
return it->second.first;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
TPropertyGroup *findWriterProperties(std::string ext) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
PropertiesTable::const_iterator it = m_writerProperties.find(ext);
|
|
Toshihiro Shimizu |
890ddd |
if (it == m_writerProperties.end())
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
return it->second;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void initialize();
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
} // namespace
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TiioTable::initialize()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Tiio::Reader *Tiio::makeReader(std::string ext)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
Tiio::ReaderMaker *reader = TiioTable::instance()->findReader(ext);
|
|
Toshihiro Shimizu |
890ddd |
if (!reader)
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
return reader();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Tiio::Writer *Tiio::makeWriter(std::string ext)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
Tiio::WriterMaker *writer = TiioTable::instance()->findWriter(ext);
|
|
Toshihiro Shimizu |
890ddd |
if (!writer)
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
return writer();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Tiio::VectorReader *Tiio::makeVectorReader(std::string ext)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
Tiio::VectorReaderMaker *reader = TiioTable::instance()->findVectorReader(ext);
|
|
Toshihiro Shimizu |
890ddd |
if (!reader)
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
return reader();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Tiio::VectorWriter *Tiio::makeVectorWriter(std::string ext)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
Tiio::VectorWriterMaker *writer = TiioTable::instance()->findVectorWriter(ext);
|
|
Toshihiro Shimizu |
890ddd |
if (!writer)
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
return writer();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPropertyGroup *Tiio::makeWriterProperties(std::string ext)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TPropertyGroup *prop = TiioTable::instance()->findWriterProperties(ext);
|
|
Toshihiro Shimizu |
890ddd |
if (!prop)
|
|
Toshihiro Shimizu |
890ddd |
return new TPropertyGroup();
|
|
Toshihiro Shimizu |
890ddd |
return prop->clone();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void Tiio::defineReaderMaker(const char *ext, Tiio::ReaderMaker *fn)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TiioTable::instance()->add(ext, fn);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void Tiio::defineWriterMaker(const char *ext, Tiio::WriterMaker *fn, bool isRenderFormat)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TiioTable::instance()->add(ext, fn, isRenderFormat);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void Tiio::defineVectorReaderMaker(const char *ext, Tiio::VectorReaderMaker *fn)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TiioTable::instance()->add(ext, fn);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void Tiio::defineVectorWriterMaker(const char *ext, Tiio::VectorWriterMaker *fn, bool isRenderFormat)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TiioTable::instance()->add(ext, fn, isRenderFormat);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void Tiio::defineWriterProperties(const char *ext, TPropertyGroup *prop)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TiioTable::instance()->addWriterProperties(ext, prop);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Shinya Kitaoka |
9f5a1b |
#ifdef _WIN32
|
|
Toshihiro Shimizu |
890ddd |
int Tiio::openForReading(char *fn)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int fd = _open(fn, _O_BINARY|_O_RDONLY);
|
|
Toshihiro Shimizu |
890ddd |
if(fd == -1)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
fprintf(stderr, "File not found\n");
|
|
Toshihiro Shimizu |
890ddd |
exit(1);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return fd;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void* Tiio::openForReading2(char *fn)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
FILE *chan = fopen(fn, "rb");
|
|
Toshihiro Shimizu |
890ddd |
if(!chan)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
fprintf(stderr, "File not found\n");
|
|
Toshihiro Shimizu |
890ddd |
exit(1);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return (void*)chan;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int Tiio::openForWriting(char *fn)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int fd = _open(
|
|
Toshihiro Shimizu |
890ddd |
fn,
|
|
Toshihiro Shimizu |
890ddd |
_O_BINARY | _O_WRONLY | _O_CREAT | _O_TRUNC,
|
|
Toshihiro Shimizu |
890ddd |
_S_IREAD | _S_IWRITE);
|
|
Toshihiro Shimizu |
890ddd |
if(fd == -1)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
fprintf(stderr, "Can't open file\n");
|
|
Toshihiro Shimizu |
890ddd |
exit(1);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return fd;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Tiio::Reader::Reader()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Tiio::Reader::~Reader()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int Tiio::Writer::m_bwThreshold = 128;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Tiio::Writer::Writer()
|
|
Toshihiro Shimizu |
890ddd |
: m_properties(0)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Tiio::Writer::~Writer()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void Tiio::Writer::getSupportedFormats(QStringList &formats, bool onlyRenderFormats)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TiioTable::VectorWriterTable::const_iterator vit = TiioTable::instance()->m_vectorWriters.begin();
|
|
Toshihiro Shimizu |
890ddd |
TiioTable::VectorWriterTable::const_iterator vit_e = TiioTable::instance()->m_vectorWriters.end();
|
|
Toshihiro Shimizu |
890ddd |
for (; vit != vit_e; ++vit)
|
|
Toshihiro Shimizu |
890ddd |
if (onlyRenderFormats && vit->second.second)
|
|
Toshihiro Shimizu |
890ddd |
formats.push_back(QString::fromStdString(vit->first));
|
|
Toshihiro Shimizu |
890ddd |
TiioTable::WriterTable::const_iterator it = TiioTable::instance()->m_writers.begin();
|
|
Toshihiro Shimizu |
890ddd |
TiioTable::WriterTable::const_iterator it_e = TiioTable::instance()->m_writers.end();
|
|
Toshihiro Shimizu |
890ddd |
for (; it != it_e; ++it)
|
|
Toshihiro Shimizu |
890ddd |
if (onlyRenderFormats && it->second.second)
|
|
Toshihiro Shimizu |
890ddd |
formats.push_back(QString::fromStdString(it->first));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void Tiio::Writer::setProperties(TPropertyGroup *properties)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_properties = properties ? properties->clone() : 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|