|
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 |
|
|
|
e280ae |
#ifdef _MSC_VER
|
|
Toshihiro Shimizu |
890ddd |
#pragma warning(disable : 4786)
|
|
|
e280ae |
#endif
|
|
|
e280ae |
|
|
|
e280ae |
#ifdef _WIN32
|
|
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 |
|
|
Shinya Kitaoka |
120a6e |
namespace {
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
class TiioTable { // singleton
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
typedef std::map<std::string, *="" tiio::readermaker=""> ReaderTable;</std::string,>
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
typedef std::map<std::string, *,="" bool="" std::pair<tiio::writermaker="">></std::string,>
|
|
Shinya Kitaoka |
120a6e |
WriterTable;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
typedef std::map<std::string, *="" tiio::vectorreadermaker=""> VectorReaderTable;</std::string,>
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
typedef std::map<std::string, *,="" bool="" std::pair<tiio::vectorwritermaker="">></std::string,>
|
|
Shinya Kitaoka |
120a6e |
VectorWriterTable;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
typedef std::map<std::string, *="" tpropertygroup=""> PropertiesTable;</std::string,>
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
ReaderTable m_readers;
|
|
Shinya Kitaoka |
120a6e |
WriterTable m_writers;
|
|
Shinya Kitaoka |
120a6e |
VectorReaderTable m_vectorReaders;
|
|
Shinya Kitaoka |
120a6e |
VectorWriterTable m_vectorWriters;
|
|
Shinya Kitaoka |
120a6e |
PropertiesTable m_writerProperties;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TiioTable() { initialize(); }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
static TiioTable *instance() {
|
|
Shinya Kitaoka |
120a6e |
static TiioTable theTable;
|
|
Shinya Kitaoka |
120a6e |
return &theTable;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
~TiioTable() {
|
|
Shinya Kitaoka |
120a6e |
for (PropertiesTable::iterator it = m_writerProperties.begin();
|
|
Shinya Kitaoka |
120a6e |
it != m_writerProperties.end(); ++it)
|
|
Shinya Kitaoka |
120a6e |
delete it->second;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void add(std::string ext, Tiio::ReaderMaker *fn) { m_readers[ext] = fn; }
|
|
Shinya Kitaoka |
120a6e |
void add(std::string ext, Tiio::WriterMaker *fn, bool isRenderFormat) {
|
|
Shinya Kitaoka |
120a6e |
m_writers[ext] = std::pair<tiio::writermaker *,="" bool="">(fn, isRenderFormat);</tiio::writermaker>
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
void add(std::string ext, Tiio::VectorReaderMaker *fn) {
|
|
Shinya Kitaoka |
120a6e |
m_vectorReaders[ext] = fn;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
void add(std::string ext, Tiio::VectorWriterMaker *fn, bool isRenderFormat) {
|
|
Shinya Kitaoka |
120a6e |
m_vectorWriters[ext] =
|
|
Shinya Kitaoka |
120a6e |
std::pair<tiio::vectorwritermaker *,="" bool="">(fn, isRenderFormat);</tiio::vectorwritermaker>
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
void addWriterProperties(std::string ext, TPropertyGroup *prop) {
|
|
Shinya Kitaoka |
120a6e |
m_writerProperties[ext] = prop;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
Tiio::ReaderMaker *findReader(std::string ext) const {
|
|
Shinya Kitaoka |
120a6e |
ReaderTable::const_iterator it = m_readers.find(ext);
|
|
Shinya Kitaoka |
120a6e |
if (it == m_readers.end())
|
|
Shinya Kitaoka |
120a6e |
return 0;
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
return it->second;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
Tiio::WriterMaker *findWriter(std::string ext) const {
|
|
Shinya Kitaoka |
120a6e |
WriterTable::const_iterator it = m_writers.find(ext);
|
|
Shinya Kitaoka |
120a6e |
if (it == m_writers.end())
|
|
Shinya Kitaoka |
120a6e |
return 0;
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
return it->second.first;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
Tiio::VectorReaderMaker *findVectorReader(std::string ext) const {
|
|
Shinya Kitaoka |
120a6e |
VectorReaderTable::const_iterator it = m_vectorReaders.find(ext);
|
|
Shinya Kitaoka |
120a6e |
if (it == m_vectorReaders.end())
|
|
Shinya Kitaoka |
120a6e |
return 0;
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
return it->second;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
Tiio::VectorWriterMaker *findVectorWriter(std::string ext) const {
|
|
Shinya Kitaoka |
120a6e |
VectorWriterTable::const_iterator it = m_vectorWriters.find(ext);
|
|
Shinya Kitaoka |
120a6e |
if (it == m_vectorWriters.end())
|
|
Shinya Kitaoka |
120a6e |
return 0;
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
return it->second.first;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
TPropertyGroup *findWriterProperties(std::string ext) const {
|
|
Shinya Kitaoka |
120a6e |
PropertiesTable::const_iterator it = m_writerProperties.find(ext);
|
|
Shinya Kitaoka |
120a6e |
if (it == m_writerProperties.end())
|
|
Shinya Kitaoka |
120a6e |
return 0;
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
return it->second;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void initialize();
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
} // namespace
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TiioTable::initialize() {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
Tiio::Reader *Tiio::makeReader(std::string ext) {
|
|
Shinya Kitaoka |
120a6e |
Tiio::ReaderMaker *reader = TiioTable::instance()->findReader(ext);
|
|
Shinya Kitaoka |
120a6e |
if (!reader)
|
|
Shinya Kitaoka |
120a6e |
return 0;
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
return reader();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
Tiio::Writer *Tiio::makeWriter(std::string ext) {
|
|
Shinya Kitaoka |
120a6e |
Tiio::WriterMaker *writer = TiioTable::instance()->findWriter(ext);
|
|
Shinya Kitaoka |
120a6e |
if (!writer)
|
|
Shinya Kitaoka |
120a6e |
return 0;
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
return writer();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
Tiio::VectorReader *Tiio::makeVectorReader(std::string ext) {
|
|
Shinya Kitaoka |
120a6e |
Tiio::VectorReaderMaker *reader =
|
|
Shinya Kitaoka |
120a6e |
TiioTable::instance()->findVectorReader(ext);
|
|
Shinya Kitaoka |
120a6e |
if (!reader)
|
|
Shinya Kitaoka |
120a6e |
return 0;
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
return reader();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
Tiio::VectorWriter *Tiio::makeVectorWriter(std::string ext) {
|
|
Shinya Kitaoka |
120a6e |
Tiio::VectorWriterMaker *writer =
|
|
Shinya Kitaoka |
120a6e |
TiioTable::instance()->findVectorWriter(ext);
|
|
Shinya Kitaoka |
120a6e |
if (!writer)
|
|
Shinya Kitaoka |
120a6e |
return 0;
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
return writer();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TPropertyGroup *Tiio::makeWriterProperties(std::string ext) {
|
|
Shinya Kitaoka |
120a6e |
TPropertyGroup *prop = TiioTable::instance()->findWriterProperties(ext);
|
|
Shinya Kitaoka |
120a6e |
if (!prop) return new TPropertyGroup();
|
|
Shinya Kitaoka |
120a6e |
return prop->clone();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void Tiio::defineReaderMaker(const char *ext, Tiio::ReaderMaker *fn) {
|
|
Shinya Kitaoka |
120a6e |
TiioTable::instance()->add(ext, fn);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void Tiio::defineWriterMaker(const char *ext, Tiio::WriterMaker *fn,
|
|
Shinya Kitaoka |
120a6e |
bool isRenderFormat) {
|
|
Shinya Kitaoka |
120a6e |
TiioTable::instance()->add(ext, fn, isRenderFormat);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void Tiio::defineVectorReaderMaker(const char *ext,
|
|
Shinya Kitaoka |
120a6e |
Tiio::VectorReaderMaker *fn) {
|
|
Shinya Kitaoka |
120a6e |
TiioTable::instance()->add(ext, fn);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void Tiio::defineVectorWriterMaker(const char *ext, Tiio::VectorWriterMaker *fn,
|
|
Shinya Kitaoka |
120a6e |
bool isRenderFormat) {
|
|
Shinya Kitaoka |
120a6e |
TiioTable::instance()->add(ext, fn, isRenderFormat);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void Tiio::defineWriterProperties(const char *ext, TPropertyGroup *prop) {
|
|
Shinya Kitaoka |
120a6e |
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 |
}
|
|
Shinya Kitaoka |
120a6e |
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(
|
|
Shinya Kitaoka |
120a6e |
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 |
}
|
|
Shinya Kitaoka |
120a6e |
return fd;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
Tiio::Reader::Reader() {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
Tiio::Reader::~Reader() {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int Tiio::Writer::m_bwThreshold = 128;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
Tiio::Writer::Writer() : m_properties(0) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
Tiio::Writer::~Writer() {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void Tiio::Writer::getSupportedFormats(QStringList &formats,
|
|
Shinya Kitaoka |
120a6e |
bool onlyRenderFormats) {
|
|
Shinya Kitaoka |
120a6e |
TiioTable::VectorWriterTable::const_iterator vit =
|
|
Shinya Kitaoka |
120a6e |
TiioTable::instance()->m_vectorWriters.begin();
|
|
Shinya Kitaoka |
120a6e |
TiioTable::VectorWriterTable::const_iterator vit_e =
|
|
Shinya Kitaoka |
120a6e |
TiioTable::instance()->m_vectorWriters.end();
|
|
Shinya Kitaoka |
120a6e |
for (; vit != vit_e; ++vit)
|
|
Shinya Kitaoka |
120a6e |
if (onlyRenderFormats && vit->second.second)
|
|
Shinya Kitaoka |
120a6e |
formats.push_back(QString::fromStdString(vit->first));
|
|
Shinya Kitaoka |
120a6e |
TiioTable::WriterTable::const_iterator it =
|
|
Shinya Kitaoka |
120a6e |
TiioTable::instance()->m_writers.begin();
|
|
Shinya Kitaoka |
120a6e |
TiioTable::WriterTable::const_iterator it_e =
|
|
Shinya Kitaoka |
120a6e |
TiioTable::instance()->m_writers.end();
|
|
Shinya Kitaoka |
120a6e |
for (; it != it_e; ++it)
|
|
Shinya Kitaoka |
120a6e |
if (onlyRenderFormats && it->second.second)
|
|
Shinya Kitaoka |
120a6e |
formats.push_back(QString::fromStdString(it->first));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void Tiio::Writer::setProperties(TPropertyGroup *properties) {
|
|
Shinya Kitaoka |
120a6e |
m_properties = properties ? properties->clone() : 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|