Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Campbell Barton 07f3e8
#if (!(defined(x64) || defined(__LP64__) || defined(LINUX)))
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//Toonz stuff
Toshihiro Shimizu 890ddd
#include "tiio.h"
Toshihiro Shimizu 890ddd
#include "timage_io.h"
Toshihiro Shimizu 890ddd
#include "tlevel_io.h"
Toshihiro Shimizu 890ddd
#include "trasterimage.h"
Toshihiro Shimizu 890ddd
#include "traster.h"
Toshihiro Shimizu 890ddd
#include "tstream.h"
Toshihiro Shimizu 890ddd
#include "movsettings.h"
Toshihiro Shimizu 890ddd
#include "tproperty.h"
Toshihiro Shimizu 890ddd
#include "tsound.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef WIN32
Toshihiro Shimizu 890ddd
#include "../image/mov/tiio_mov.h"
Toshihiro Shimizu 890ddd
#elif MACOSX
Toshihiro Shimizu 890ddd
#include "../image/mov/tiio_movM.h"
Toshihiro Shimizu 890ddd
#include <applicationservices applicationservices.h=""></applicationservices>
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//Qt stuff
Toshihiro Shimizu 890ddd
#include <qstring></qstring>
Toshihiro Shimizu 890ddd
#include <qhash></qhash>
Toshihiro Shimizu 890ddd
#include <qsharedmemory></qsharedmemory>
Toshihiro Shimizu 890ddd
#include <qdebug></qdebug>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <qlocalsocket></qlocalsocket>
Toshihiro Shimizu 890ddd
#include <qdatastream></qdatastream>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//tipc includes
Toshihiro Shimizu 890ddd
#include "tipc.h"
Toshihiro Shimizu 890ddd
#include "tipcmsg.h"
Toshihiro Shimizu 890ddd
#include "tipcsrv.h"
Toshihiro Shimizu 890ddd
#include "t32bitsrv_wrap.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "t32movmsg.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//  Diagnostics stuff
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//#define TIPC_DEBUG
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef TIPC_DEBUG
Toshihiro Shimizu 890ddd
#define tipc_debug(expr) expr
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define tipc_debug(expr)
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef TIPC_DEBUG
Toshihiro Shimizu 890ddd
#include <qtime></qtime>
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//  Local namespace stuff
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
namespace
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
QHash<unsigned int,="" tlevelreaderp=""> readers;</unsigned>
Toshihiro Shimizu 890ddd
QHash<unsigned int,="" tlevelwriterp=""> writers;</unsigned>
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using namespace tipc;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
namespace mov_io
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void addParsers(tipc::Server *srv)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	srv->addParser(new IsQTInstalledParser);
Toshihiro Shimizu 890ddd
	srv->addParser(new DefaultMovPropsParser);
Toshihiro Shimizu 890ddd
	srv->addParser(new OpenMovSettingsPopupParser);
Toshihiro Shimizu 890ddd
	srv->addParser(new InitLWMovParser);
Toshihiro Shimizu 890ddd
	srv->addParser(new LWSetFrameRateParser);
Toshihiro Shimizu 890ddd
	srv->addParser(new LWImageWriteParser);
Toshihiro Shimizu 890ddd
	srv->addParser(new LWSaveSoundTrackParser);
Toshihiro Shimizu 890ddd
	srv->addParser(new CloseLWMovParser);
Toshihiro Shimizu 890ddd
	srv->addParser(new InitLRMovParser);
Toshihiro Shimizu 890ddd
	srv->addParser(new LRLoadInfoParser);
Toshihiro Shimizu 890ddd
	srv->addParser(new LREnableRandomAccessReadParser);
Toshihiro Shimizu 890ddd
	srv->addParser(new LRImageReadParser);
Toshihiro Shimizu 890ddd
	srv->addParser(new LRImageReadSHMParser);
Toshihiro Shimizu 890ddd
	srv->addParser(new CloseLRMovParser);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef WIN32
Toshihiro Shimizu 890ddd
	srv->addParser(new LRSetYMirrorParser);
Toshihiro Shimizu 890ddd
	srv->addParser(new LRSetLoadTimecodeParser);
Toshihiro Shimizu 890ddd
	srv->addParser(new LRTimecodeParser);
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
//    IsQTInstalled Parser
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void IsQTInstalledParser::operator()(Message &msg)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	bool ret = Tiio::isQuicktimeInstalled();
Toshihiro Shimizu 890ddd
	msg << clr << QString((ret) ? "yes" : "no");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
//    DefaultMovProps Parser
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void DefaultMovPropsParser::operator()(Message &msg)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	//Ensure the file path was passed - and retrieve it
Toshihiro Shimizu 890ddd
	QString reply;
Toshihiro Shimizu 890ddd
	msg >> reply >> clr;
Toshihiro Shimizu 890ddd
	if (reply.isEmpty())
Toshihiro Shimizu 890ddd
		goto err;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef WIN32
Toshihiro Shimizu 890ddd
	//Ensure that QuickTime is correctly running
Toshihiro Shimizu 890ddd
	if (InitializeQTML(0) != noErr)
Toshihiro Shimizu 890ddd
		goto err;
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//Success - retrieve the props
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		TPropertyGroup movProps;
Toshihiro Shimizu 890ddd
		{
Toshihiro Shimizu 890ddd
			//Low-level QuickTime stuff
Toshihiro Shimizu 890ddd
			ComponentInstance ci = OpenDefaultComponent(StandardCompressionType, StandardCompressionSubType);
Toshihiro Shimizu 890ddd
			QTAtomContainer settings;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			if (SCGetSettingsAsAtomContainer(ci, &settings) != noErr)
Toshihiro Shimizu 890ddd
				assert(false);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			fromAtomsToProperties(settings, movProps);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		//Write the retrieved properties
Toshihiro Shimizu 890ddd
		TFilePath tfp(reply.toStdWString());
Toshihiro Shimizu 890ddd
		TOStream os(tfp);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		movProps.saveData(os);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		msg << QString("ok");
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
err:
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	msg << QString("err");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
//    OpenMovSettingsPopup Parser
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void OpenMovSettingsPopupParser::operator()(Message &msg)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	//Open the properties file
Toshihiro Shimizu 890ddd
	QString fp;
Toshihiro Shimizu 890ddd
	msg >> fp >> clr;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//Retrieve the properties
Toshihiro Shimizu 890ddd
	TPropertyGroup *props = new TPropertyGroup;
Toshihiro Shimizu 890ddd
	TFilePath tfp(fp.toStdWString());
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		TIStream is(tfp);
Toshihiro Shimizu 890ddd
		props->loadData(is);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef MACOSX
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	ProcessSerialNumber psn = {0, kCurrentProcess};
Toshihiro Shimizu 890ddd
	TransformProcessType(&psn, kProcessTransformToForegroundApplication);
Toshihiro Shimizu 890ddd
	SetFrontProcess(&psn);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	openMovSettingsPopup(props, true);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		TOStream os(tfp); //Should NOT append
Toshihiro Shimizu 890ddd
		props->saveData(os);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	delete props;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	msg << QString("ok");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
//    InitLWMov Parser
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void InitLWMovParser::operator()(Message &msg)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	unsigned int id;
Toshihiro Shimizu 890ddd
	QString fp, propsFp;
Toshihiro Shimizu 890ddd
	msg >> id >> fp >> propsFp >> clr;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TFilePath tfp(fp.toStdWString()), propsTFp(propsFp.toStdWString());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	try {
Toshihiro Shimizu 890ddd
		TPropertyGroup *props = 0;
Toshihiro Shimizu 890ddd
		if (!propsTFp.isEmpty()) {
Toshihiro Shimizu 890ddd
			props = new TPropertyGroup;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			TIStream is(propsTFp);
Toshihiro Shimizu 890ddd
			props->loadData(is);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		writers.insert(id, TLevelWriterP(tfp, props));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		msg << QString("ok");
Toshihiro Shimizu 890ddd
	} catch (...) {
Toshihiro Shimizu 890ddd
		msg << QString("err");
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
//    LWsetFrameRate Parser
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void LWSetFrameRateParser::operator()(Message &msg)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	unsigned int id;
Toshihiro Shimizu 890ddd
	double fps;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	msg >> id >> fps >> clr;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	writers.find(id).value()->setFrameRate(fps);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	msg << QString("ok");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
//    LWImageWrite Parser
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void LWImageWriteParser::operator()(Message &msg)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	unsigned int id;
Toshihiro Shimizu 890ddd
	int frameIdx, lx, ly;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	msg >> id >> frameIdx >> lx >> ly;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//Read the data through a shared memory segment
Toshihiro Shimizu 890ddd
	TRaster32P ras(lx, ly);
Toshihiro Shimizu 890ddd
	t32bitsrv::RasterExchanger<tpixel32> exch(ras);</tpixel32>
Toshihiro Shimizu 890ddd
	tipc::readShMemBuffer(*stream(), msg, &exch);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//Save the image
Toshihiro Shimizu 890ddd
	try {
Toshihiro Shimizu 890ddd
		TImageWriterP iw(writers.find(id).value()->getFrameWriter(frameIdx + 1));
Toshihiro Shimizu 890ddd
		iw->save(TRasterImageP(ras));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		msg << QString("ok");
Toshihiro Shimizu 890ddd
	} catch (...) {
Toshihiro Shimizu 890ddd
		msg << QString("err");
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
//    LWSaveSoundTrack Parser
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void LWSaveSoundTrackParser::operator()(Message &msg)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	unsigned int id;
Toshihiro Shimizu 890ddd
	QString shMemId;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TUINT32 sampleRate;
Toshihiro Shimizu 890ddd
	TINT32 sCount;
Toshihiro Shimizu 890ddd
	int bps, chanCount;
Toshihiro Shimizu 890ddd
	bool signedSample;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	msg >> id >> sampleRate >> bps >> chanCount >> sCount >> signedSample;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//Retrieve the soundtrack buffer
Toshihiro Shimizu 890ddd
	TSoundTrackP st = TSoundTrack::create(sampleRate, bps, chanCount, sCount, signedSample);
Toshihiro Shimizu 890ddd
	t32bitsrv::BufferExchanger exch((UCHAR *)st->getRawData());
Toshihiro Shimizu 890ddd
	tipc::readShMemBuffer(*stream(), msg, &exch);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//Write the soundtrack
Toshihiro Shimizu 890ddd
	try {
Toshihiro Shimizu 890ddd
		writers.find(id).value()->saveSoundTrack(st.getPointer());
Toshihiro Shimizu 890ddd
		msg << QString("ok");
Toshihiro Shimizu 890ddd
	} catch (...) {
Toshihiro Shimizu 890ddd
		msg << QString("err");
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
//    CloseLWMov Parser
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void CloseLWMovParser::operator()(Message &msg)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	unsigned int id;
Toshihiro Shimizu 890ddd
	msg >> id >> clr;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	try {
Toshihiro Shimizu 890ddd
		writers.take(id);
Toshihiro Shimizu 890ddd
		msg << QString("ok");
Toshihiro Shimizu 890ddd
	} catch (...) {
Toshihiro Shimizu 890ddd
		msg << QString("err");
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
//    InitLRMov Parser
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void InitLRMovParser::operator()(Message &msg)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	unsigned int id;
Toshihiro Shimizu 890ddd
	QString fp, propsFp;
Toshihiro Shimizu 890ddd
	msg >> id >> fp >> clr;
Toshihiro Shimizu 890ddd
	assert(!fp.isEmpty());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TFilePath tfp(fp.toStdWString());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	try {
Toshihiro Shimizu 890ddd
		TLevelReaderP lrm(tfp);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		//Extract some info to be returned
Toshihiro Shimizu 890ddd
		const TImageInfo *info = lrm->getImageInfo();
Toshihiro Shimizu 890ddd
		if (!info)
Toshihiro Shimizu 890ddd
			throw TImageException(tfp, "Couldn't retrieve image properties");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		int lx = info->m_lx, ly = info->m_ly;
Toshihiro Shimizu 890ddd
		double frameRate = info->m_frameRate;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		tipc_debug(qDebug() << "Inserted image" << QString::fromStdWString(tfp.getWideString()));
Toshihiro Shimizu 890ddd
		readers.insert(id, lrm);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		msg << QString("ok") << lx << ly << frameRate;
Toshihiro Shimizu 890ddd
	} catch (...) {
Toshihiro Shimizu 890ddd
		msg << QString("err");
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
//    LRLoadInfo Parser
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void LRLoadInfoParser::operator()(Message &msg)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	//Read command data
Toshihiro Shimizu 890ddd
	unsigned int id;
Toshihiro Shimizu 890ddd
	QString shMemId;
Toshihiro Shimizu 890ddd
	msg >> id >> shMemId >> clr;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QHash<unsigned int,="" tlevelreaderp="">::iterator it = readers.find(id);</unsigned>
Toshihiro Shimizu 890ddd
	if (it == readers.end())
Toshihiro Shimizu 890ddd
		goto err;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//Read level infos
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		TLevelP level;
Toshihiro Shimizu 890ddd
		try {
Toshihiro Shimizu 890ddd
			level = it.value()->loadInfo();
Toshihiro Shimizu 890ddd
		} catch (...) {
Toshihiro Shimizu 890ddd
			goto err;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		int frameCount = level->getFrameCount();
Toshihiro Shimizu 890ddd
		if (!shMemId.isEmpty()) {
Toshihiro Shimizu 890ddd
			//Create a shared memory segment to transfer the infos to
Toshihiro Shimizu 890ddd
			tipc::DefaultMessageParser<shmem_request> msgParser;</shmem_request>
Toshihiro Shimizu 890ddd
			Message shMsg;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			shMsg << shMemId << frameCount * (int)sizeof(int) << reset;
Toshihiro Shimizu 890ddd
			msgParser(shMsg);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			QString str;
Toshihiro Shimizu 890ddd
			shMsg >> reset >> str;
Toshihiro Shimizu 890ddd
			if (str != QString("ok"))
Toshihiro Shimizu 890ddd
				goto err;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			//Copy level data to the shared memory segment
Toshihiro Shimizu 890ddd
			{
Toshihiro Shimizu 890ddd
				QSharedMemory shmem(shMemId);
Toshihiro Shimizu 890ddd
				shmem.attach();
Toshihiro Shimizu 890ddd
				shmem.lock();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				TLevel::Table *table = level->getTable();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				TLevel::Table::const_iterator jt;
Toshihiro Shimizu 890ddd
				int *f = (int *)shmem.data();
Toshihiro Shimizu 890ddd
				for (jt = table->begin(); jt != table->end(); ++jt, ++f)
Toshihiro Shimizu 890ddd
					*f = jt->first.getNumber();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				shmem.unlock();
Toshihiro Shimizu 890ddd
				shmem.detach();
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		msg << QString("ok") << frameCount;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
err:
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	msg << QString("err");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
//    LREnableRandomAccessRead Parser
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void LREnableRandomAccessReadParser::operator()(Message &msg)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	unsigned int id;
Toshihiro Shimizu 890ddd
	QString str;
Toshihiro Shimizu 890ddd
	msg >> id >> str >> clr;
Toshihiro Shimizu 890ddd
	bool enable = (str == "true");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QHash<unsigned int,="" tlevelreaderp="">::iterator it = readers.find(id);</unsigned>
Toshihiro Shimizu 890ddd
	if (it == readers.end()) {
Toshihiro Shimizu 890ddd
		msg << QString("err");
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	it.value()->enableRandomAccessRead(enable);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	msg << QString("ok");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
//    LRSetYMirror Parser
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef WIN32
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void LRSetYMirrorParser::operator()(Message &msg)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	unsigned int id;
Toshihiro Shimizu 890ddd
	QString str;
Toshihiro Shimizu 890ddd
	msg >> id >> str >> clr;
Toshihiro Shimizu 890ddd
	bool enable = (str == "true");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QHash<unsigned int,="" tlevelreaderp="">::iterator it = readers.find(id);</unsigned>
Toshihiro Shimizu 890ddd
	if (it == readers.end()) {
Toshihiro Shimizu 890ddd
		msg << QString("err");
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	static_cast<tlevelreadermov *="">(it.value().getPointer())->setYMirror(enable);</tlevelreadermov>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	msg << QString("ok");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
//    LRSetLoadTimecode Parser
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void LRSetLoadTimecodeParser::operator()(Message &msg)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	unsigned int id;
Toshihiro Shimizu 890ddd
	QString str;
Toshihiro Shimizu 890ddd
	msg >> id >> str >> clr;
Toshihiro Shimizu 890ddd
	bool enable = (str == "true");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QHash<unsigned int,="" tlevelreaderp="">::iterator it = readers.find(id);</unsigned>
Toshihiro Shimizu 890ddd
	if (it == readers.end()) {
Toshihiro Shimizu 890ddd
		msg << QString("err");
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	static_cast<tlevelreadermov *="">(it.value().getPointer())->setLoadTimecode(enable);</tlevelreadermov>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	msg << QString("ok");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
//    LRTimecode Parser
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void LRTimecodeParser::operator()(Message &msg)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	unsigned int id;
Toshihiro Shimizu 890ddd
	int frameIdx;
Toshihiro Shimizu 890ddd
	QString str;
Toshihiro Shimizu 890ddd
	msg >> id >> frameIdx >> clr;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QHash<unsigned int,="" tlevelreaderp="">::iterator it = readers.find(id);</unsigned>
Toshihiro Shimizu 890ddd
	if (it == readers.end()) {
Toshihiro Shimizu 890ddd
		msg << QString("err");
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	UCHAR hh, mm, ss, ff;
Toshihiro Shimizu 890ddd
	static_cast<tlevelreadermov *="">(it.value().getPointer())->timecode(frameIdx, hh, mm, ss, ff);</tlevelreadermov>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	msg << QString("ok") << hh << mm << ss << ff;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
//    LRImageRead Parser
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void LRImageReadParser::operator()(Message &msg)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	tipc_debug(
Toshihiro Shimizu 890ddd
		QTime fTime; QTime irTime; QTime shTime;
Toshihiro Shimizu 890ddd
		fTime.start(););
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		unsigned int id;
Toshihiro Shimizu 890ddd
		int lx, ly, pixSize, frameIdx, x, y, shrinkX, shrinkY;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		msg >> id >> lx >> ly >> pixSize >> frameIdx >> x >> y >> shrinkX >> shrinkY >> clr;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (pixSize != 4)
Toshihiro Shimizu 890ddd
			goto err;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		QHash<unsigned int,="" tlevelreaderp="">::iterator it = readers.find(id);</unsigned>
Toshihiro Shimizu 890ddd
		if (it == readers.end())
Toshihiro Shimizu 890ddd
			goto err;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		tipc_debug(irTime.start());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		//Load the raster
Toshihiro Shimizu 890ddd
		TRaster32P ras(lx, ly);
Toshihiro Shimizu 890ddd
		try {
Toshihiro Shimizu 890ddd
			TImageReaderP ir(it.value()->getFrameReader(frameIdx + 1));
Toshihiro Shimizu 890ddd
			ir->load(ras, TPoint(x, y), shrinkX, shrinkY);
Toshihiro Shimizu 890ddd
		} catch (...) {
Toshihiro Shimizu 890ddd
			goto err;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		tipc_debug(qDebug() << "load time:" << irTime.elapsed());
Toshihiro Shimizu 890ddd
		tipc_debug(shTime.start());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		t32bitsrv::RasterExchanger<tpixel32> exch(ras);</tpixel32>
Toshihiro Shimizu 890ddd
		if (!tipc::writeShMemBuffer(*stream(), msg << clr, lx * ly * sizeof(TPixel32), &exch))
Toshihiro Shimizu 890ddd
			goto err;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		tipc_debug(qDebug() << "exchange time:" << shTime.elapsed());
Toshihiro Shimizu 890ddd
		tipc_debug(qDebug() << "TLevelReaderMov::loadImage time:" << fTime.elapsed());
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
err:
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	msg << QString("err");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
//    LRImageReadSHM Parser
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void LRImageReadSHMParser::operator()(Message &msg)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	tipc_debug(
Toshihiro Shimizu 890ddd
		QTime fTime; QTime irTime;
Toshihiro Shimizu 890ddd
		fTime.start(););
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	unsigned int id;
Toshihiro Shimizu 890ddd
	int lx, ly, frameIdx;
Toshihiro Shimizu 890ddd
	QString shMemId;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	msg >> id >> lx >> ly >> frameIdx >> shMemId >> clr;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	tipc_debug(qDebug() << "LoadImageSHM data:" << id << lx << ly << frameIdx << shMemId);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QHash<unsigned int,="" tlevelreaderp="">::iterator it = readers.find(id);</unsigned>
Toshihiro Shimizu 890ddd
	if (it == readers.end())
Toshihiro Shimizu 890ddd
		goto err;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//Attach the shared memory segment the raster
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		QSharedMemory shm(shMemId);
Toshihiro Shimizu 890ddd
		shm.attach();
Toshihiro Shimizu 890ddd
		if (!shm.isAttached())
Toshihiro Shimizu 890ddd
			goto err;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		//Load the raster
Toshihiro Shimizu 890ddd
		TRaster32P ras(lx, ly, lx, (TPixel32 *)shm.data());
Toshihiro Shimizu 890ddd
		try {
Toshihiro Shimizu 890ddd
			tipc_debug(qDebug() << "loading image...");
Toshihiro Shimizu 890ddd
			tipc_debug(irTime.start());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			shm.lock();
Toshihiro Shimizu 890ddd
			TImageReaderP ir(it.value()->getFrameReader(frameIdx + 1));
Toshihiro Shimizu 890ddd
			ir->load(ras, TPoint(), 1, 1);
Toshihiro Shimizu 890ddd
			shm.unlock();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			tipc_debug(qDebug() << "load time:" << irTime.elapsed());
Toshihiro Shimizu 890ddd
		} catch (TImageException e) {
Toshihiro Shimizu 890ddd
			shm.unlock();
Toshihiro Shimizu 890ddd
			tipc_debug(qDebug() << "Image Read Error:" << QString::fromStdWString(e.getMessage()));
Toshihiro Shimizu 890ddd
			goto err;
Toshihiro Shimizu 890ddd
		} catch (...) {
Toshihiro Shimizu 890ddd
			shm.unlock();
Toshihiro Shimizu 890ddd
			tipc_debug(qDebug() << "Unknown Image Read Error");
Toshihiro Shimizu 890ddd
			goto err;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	msg << QString("ok");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef WIN32
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	UCHAR hh, mm, ss, ff;
Toshihiro Shimizu 890ddd
	TLevelReaderMov *lrm = static_cast<tlevelreadermov *="">(it.value().getPointer());</tlevelreadermov>
Toshihiro Shimizu 890ddd
	lrm->loadedTimecode(hh, mm, ss, ff);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	tipc_debug(qDebug() << "TLevelReaderMov::loadImage time:" << fTime.elapsed());
Toshihiro Shimizu 890ddd
	msg << hh << mm << ss << ff;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
err:
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	msg << QString("err");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
//    CloseLRMov Parser
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void CloseLRMovParser::operator()(Message &msg)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	unsigned int id;
Toshihiro Shimizu 890ddd
	msg >> id >> clr;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	readers.take(id);
Toshihiro Shimizu 890ddd
	msg << QString("ok");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
} //namespace mov_io
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif // !x64 && !__LP64__