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