2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
|
|
#ifndef x64
|
|
|
|
|
|
|
|
#include "texception.h"
|
|
|
|
#include "tsound.h"
|
|
|
|
#include "tconvert.h"
|
|
|
|
#include "tpropertytype.h"
|
|
|
|
#include "timageinfo.h"
|
|
|
|
#include "tlevel_io.h"
|
|
|
|
#include "../avi/tiio_avi.h"
|
|
|
|
#include "trasterimage.h"
|
|
|
|
|
|
|
|
#include "tiio_mov.h"
|
|
|
|
#include "movsettings.h"
|
|
|
|
|
|
|
|
//**************************************************************************************
|
|
|
|
// Local namespace stuff
|
|
|
|
//**************************************************************************************
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
namespace {
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
const std::string firstFrameKey = "frst"; // First frame atom id
|
|
|
|
const int firstFrameKeySize = 4 * sizeof(char); //
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class QuickTimeCleanUp;
|
2016-06-15 18:43:10 +12:00
|
|
|
class QuickTimeStuff {
|
2016-03-19 06:57:51 +13:00
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
static QuickTimeStuff *instance() {
|
|
|
|
if (!m_singleton) m_singleton = new QuickTimeStuff();
|
|
|
|
return m_singleton;
|
|
|
|
}
|
|
|
|
OSErr getStatus() { return m_status; }
|
|
|
|
~QuickTimeStuff() {}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
private:
|
2016-06-15 18:43:10 +12:00
|
|
|
QuickTimeStuff() : m_status(noErr) {
|
|
|
|
m_status = InitializeQTML(0);
|
|
|
|
EnterMovies();
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
static QuickTimeStuff *m_singleton;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
OSErr m_status;
|
|
|
|
friend class QuickTimeCleanUp; // questa DEVE essere friend, cosi' posso
|
|
|
|
// controllare direttamente
|
|
|
|
// lo stato del singleton.
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
class QuickTimeCleanUp {
|
2016-03-19 06:57:51 +13:00
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
QuickTimeCleanUp() {}
|
|
|
|
~QuickTimeCleanUp() { /*
|
|
|
|
Nel caso si arrivasse qui senza il
|
|
|
|
singleton instanziato, e si facesse direttamente
|
|
|
|
'delete QuickTimeStuff::instance();'
|
|
|
|
Quicktime non farebbe in tempo a terminare le
|
|
|
|
sue routine di inizializzazione (che sono
|
|
|
|
ANCHE su altri thread) e la chiamata a
|
|
|
|
TerminateQTML() causerebbe un crash
|
|
|
|
*/
|
|
|
|
if (QuickTimeStuff::m_singleton) delete QuickTimeStuff::m_singleton;
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
QuickTimeCleanUp cleanUp;
|
|
|
|
QuickTimeStuff *QuickTimeStuff::m_singleton = 0;
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
enum QTLibError {
|
2016-06-15 18:43:10 +12:00
|
|
|
QTNoError = 0x0000,
|
|
|
|
QTNotInstalled,
|
|
|
|
QTUnknownError,
|
|
|
|
QTUnableToOpenFile,
|
|
|
|
QTCantCreateFile,
|
|
|
|
QTUnableToGetCompressorNames,
|
|
|
|
QTUnableToCreateResource,
|
|
|
|
QTUnableToUpdateMovie,
|
|
|
|
QTBadTimeValue,
|
|
|
|
QTUnableToDoMovieTask,
|
|
|
|
QTUnableToSetTimeValue,
|
|
|
|
QTUnableToSetMovieGWorld,
|
|
|
|
QTUnableToSetMovieBox,
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
string buildQTErrorString(int ec) {
|
|
|
|
switch (ec) {
|
|
|
|
case QTNotInstalled:
|
|
|
|
return "Can't create; ensure that quicktime is correctly installed on your "
|
|
|
|
"machine";
|
|
|
|
case QTUnknownError:
|
|
|
|
return "Unknown error";
|
|
|
|
case QTUnableToOpenFile:
|
|
|
|
return "can't open file";
|
|
|
|
case QTCantCreateFile:
|
|
|
|
return "can't create movie";
|
|
|
|
case QTUnableToGetCompressorNames:
|
|
|
|
return "unable to get compressor name";
|
|
|
|
case QTUnableToCreateResource:
|
|
|
|
return "can't create resource";
|
|
|
|
case QTUnableToUpdateMovie:
|
|
|
|
return "unable to update movie";
|
|
|
|
case QTBadTimeValue:
|
|
|
|
return "bad frame number";
|
|
|
|
case QTUnableToDoMovieTask:
|
|
|
|
return "unable to do movie task";
|
|
|
|
case QTUnableToSetTimeValue:
|
|
|
|
return "unable to set time value";
|
|
|
|
case QTUnableToSetMovieGWorld:
|
|
|
|
return "unable to set movie graphic world";
|
|
|
|
case QTUnableToSetMovieBox:
|
|
|
|
return "unable to set movie box";
|
|
|
|
|
|
|
|
default: { return "unknown error ('" + std::to_string(ec) + "')"; }
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
inline LPSTR AtlW2AHelper(LPSTR lpa, LPCWSTR lpw, int nChars, UINT acp) {
|
|
|
|
assert(lpw != NULL);
|
|
|
|
assert(lpa != NULL);
|
|
|
|
// verify that no illegal character present
|
|
|
|
// since lpa was allocated based on the size of lpw
|
|
|
|
// don't worry about the number of chars
|
|
|
|
lpa[0] = '\0';
|
|
|
|
WideCharToMultiByte(acp, 0, lpw, -1, lpa, nChars, NULL, NULL);
|
|
|
|
return lpa;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
inline char *filePath2unichar(const TFilePath &path) {
|
|
|
|
int _convert = 0;
|
|
|
|
std::wstring ws = path.getWideString();
|
|
|
|
|
|
|
|
LPCWSTR lpw = ws.c_str();
|
|
|
|
char *name = NULL;
|
|
|
|
|
|
|
|
if (lpw) {
|
|
|
|
_convert = (lstrlenW(lpw) + 1) * 2;
|
|
|
|
LPSTR pStr = new char[_convert];
|
|
|
|
name = AtlW2AHelper(pStr, lpw, _convert, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
char *outName = new char[1024];
|
|
|
|
|
|
|
|
if (QTMLGetCanonicalPathName(name, outName, 1024) == noErr) {
|
|
|
|
delete[] name;
|
|
|
|
return outName;
|
|
|
|
}
|
|
|
|
delete[] outName;
|
|
|
|
return name;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TFilePath getLegalName(const TFilePath &name) {
|
|
|
|
if (QuickTimeStuff::instance()->getStatus() != noErr) return name;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TFilePath legalName;
|
|
|
|
char outDir[1024];
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TFilePath dirName(name.getParentDir());
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
char dirNameFp[1024] = "";
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
OSErr err = QTMLGetCanonicalPathName(dirNameFp, outDir, 1024);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
if (err == noErr)
|
|
|
|
legalName = TFilePath(outDir) + name.withoutParentDir();
|
|
|
|
else
|
|
|
|
legalName = name;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
return legalName;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
string long2fourchar(TINT32 fcc) {
|
|
|
|
string s;
|
|
|
|
s += (char((fcc & 0xff000000) >> 24));
|
|
|
|
s += (char((fcc & 0x00ff0000) >> 16));
|
|
|
|
s += (char((fcc & 0x0000ff00) >> 8));
|
|
|
|
s += (char((fcc & 0x000000ff) >> 0));
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
return s;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TimeScale frameRateToTimeScale(double frameRate) {
|
|
|
|
return tround(frameRate * 100.0);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
// const std::string CodecNamesId = "PU_CodecName";
|
|
|
|
// const std::string CodecQualityId = "PU_CodecQuality";
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
} // namespace
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
bool IsQuickTimeInstalled() {
|
|
|
|
return QuickTimeStuff::instance()->getStatus() == noErr;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// TImageWriterMov
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2016-06-29 18:17:12 +12:00
|
|
|
class TImageWriterMov final : public TImageWriter {
|
2016-03-19 06:57:51 +13:00
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
TImageWriterMov(const TFilePath &, int frameIndex, TLevelWriterMov *);
|
|
|
|
~TImageWriterMov() { m_lwm->release(); }
|
2016-06-19 20:06:29 +12:00
|
|
|
bool is64bitOutputSupported() override { return false; }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
private:
|
2016-06-15 18:43:10 +12:00
|
|
|
// not implemented
|
|
|
|
TImageWriterMov(const TImageWriterMov &);
|
|
|
|
TImageWriterMov &operator=(const TImageWriterMov &src);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
public:
|
2016-06-19 20:06:29 +12:00
|
|
|
void save(const TImageP &) override;
|
2016-06-15 18:43:10 +12:00
|
|
|
int m_frameIndex;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
private:
|
2016-06-15 18:43:10 +12:00
|
|
|
TLevelWriterMov *m_lwm;
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
//-----------------------------------------------------------
|
|
|
|
//-----------------------------------------------------------
|
|
|
|
// TImageWriterMov
|
|
|
|
//-----------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TImageWriterMov::TImageWriterMov(const TFilePath &path, int frameIndex,
|
|
|
|
TLevelWriterMov *lwm)
|
|
|
|
: TImageWriter(path), m_lwm(lwm), m_frameIndex(frameIndex) {
|
|
|
|
m_lwm->addRef();
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------
|
2016-06-15 18:43:10 +12:00
|
|
|
namespace {
|
|
|
|
void copy(TRasterP rin, PixelXRGB *bufout, int lx, int ly) {
|
|
|
|
TRaster32P rin32 = rin;
|
|
|
|
assert(rin32);
|
|
|
|
|
|
|
|
PixelXRGB *rowout = &(bufout[(ly - 1) * lx]);
|
|
|
|
rin32->lock();
|
|
|
|
for (int y = 0; y < rin32->getLy(); y++) {
|
|
|
|
PixelXRGB *pixout = rowout;
|
|
|
|
TPixelRGBM32 *pixin = rin32->pixels(y);
|
|
|
|
TPixelRGBM32 *pixinEnd = pixin + rin32->getLx();
|
|
|
|
while (pixin < pixinEnd) {
|
|
|
|
pixout->x = pixin->m;
|
|
|
|
pixout->r = pixin->r;
|
|
|
|
pixout->g = pixin->g;
|
|
|
|
pixout->b = pixin->b;
|
|
|
|
pixout++;
|
|
|
|
pixin++;
|
|
|
|
}
|
|
|
|
rowout -= lx;
|
|
|
|
}
|
|
|
|
rin32->unlock();
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//-----------------------------------------------------------
|
|
|
|
/*
|
2016-04-19 19:32:17 +12:00
|
|
|
TWriterInfo *TWriterInfoMov::create(const std::string &)
|
2016-03-19 06:57:51 +13:00
|
|
|
{
|
|
|
|
return new TWriterInfoMov();
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------
|
|
|
|
|
|
|
|
TWriterInfoMov::TWriterInfoMov(const TWriterInfoMov&src)
|
|
|
|
:TWriterInfo(src)
|
|
|
|
,m_codecTable(src.m_codecTable)
|
|
|
|
,m_qualityTable(src.m_qualityTable)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------
|
|
|
|
|
|
|
|
TWriterInfo *TWriterInfoMov::clone() const
|
|
|
|
{
|
|
|
|
return new TWriterInfoMov(*this);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
//-----------------------------------------------------------
|
|
|
|
/*
|
2016-06-29 18:17:12 +12:00
|
|
|
class MovWriterProperties final : public TPropertyGroup {
|
2016-03-19 06:57:51 +13:00
|
|
|
public:
|
|
|
|
TEnumProperty m_codec;
|
|
|
|
TEnumProperty m_quality;
|
|
|
|
|
|
|
|
|
|
|
|
Tiio::TifWriterProperties::TifWriterProperties()
|
|
|
|
: m_byteOrdering("Byte Order")
|
|
|
|
, m_compressionType("Compression Type")
|
|
|
|
, m_matte("Alpha Channel", true)
|
|
|
|
{
|
|
|
|
m_byteOrdering.addValue(L"IBM PC");
|
|
|
|
m_byteOrdering.addValue(L"Mac");
|
2016-04-15 17:11:23 +12:00
|
|
|
#ifdef _WIN32
|
2016-03-19 06:57:51 +13:00
|
|
|
m_byteOrdering.setValue(L"IBM PC");
|
|
|
|
#else
|
|
|
|
m_byteOrdering.setValue(L"Mac");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
m_compressionType.addValue(L"NONE");
|
|
|
|
m_compressionType.addValue(L"LZW");
|
|
|
|
|
|
|
|
bind(m_byteOrdering);
|
|
|
|
bind(m_matte);
|
|
|
|
bind(m_compressionType);
|
|
|
|
m_compressionType.setValue(L"LZW");
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
//-----------------------------------------------------------
|
|
|
|
/*
|
|
|
|
CodecType Tiio::MovWriterProperties::getCurrentCodec()const
|
|
|
|
{
|
|
|
|
std::map<wstring, CodecType>::const_iterator it;
|
|
|
|
|
|
|
|
it = m_codecMap.find(m_codec.getValue());
|
|
|
|
assert(it!=m_codecMap.end());
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
wstring Tiio::MovWriterProperties::getCurrentNameFromCodec(CodecType
|
|
|
|
&cCodec)const
|
2016-03-19 06:57:51 +13:00
|
|
|
{
|
|
|
|
std::map<wstring, CodecType>::const_iterator it;
|
|
|
|
|
|
|
|
for(it=m_codecMap.begin();it!=m_codecMap.end();++it)
|
|
|
|
{
|
|
|
|
CodecType tmp=it->second;
|
|
|
|
if(it->second==cCodec) break;
|
|
|
|
}
|
|
|
|
assert(it!=m_codecMap.end());
|
|
|
|
return it->first;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
wstring Tiio::MovWriterProperties::getCurrentQualityFromCodeQ(CodecQ
|
|
|
|
&cCodecQ)const
|
2016-03-19 06:57:51 +13:00
|
|
|
{
|
|
|
|
std::map<wstring, CodecQ>::const_iterator it;
|
|
|
|
|
|
|
|
for(it=m_qualityMap.begin();it!=m_qualityMap.end();++it)
|
|
|
|
{
|
|
|
|
CodecQ tmp=it->second;
|
|
|
|
if(it->second==cCodecQ) break;
|
|
|
|
}
|
|
|
|
assert(it!=m_qualityMap.end());
|
|
|
|
return it->first;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------
|
|
|
|
|
|
|
|
CodecQ Tiio::MovWriterProperties::getCurrentQuality() const
|
|
|
|
{
|
|
|
|
std::map<wstring, CodecQ>::const_iterator it;
|
|
|
|
|
|
|
|
it = m_qualityMap.find(m_quality.getValue());
|
|
|
|
assert(it!=m_qualityMap.end());
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
//-----------------------------------------------------------
|
|
|
|
|
|
|
|
/*
|
|
|
|
TPropertyGroup* Tiio::MovWriterProperties::clone() const
|
|
|
|
{
|
|
|
|
MovWriterProperties*g = new MovWriterProperties();
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
g->m_codec.setValue(m_codec.getValue());
|
|
|
|
g->m_quality.setValue(m_quality.getValue());
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
return (TPropertyGroup*)g;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
Tiio::MovWriterProperties::MovWriterProperties()
|
|
|
|
//: m_codec("Codec")
|
|
|
|
//, m_quality("Quality")
|
|
|
|
{
|
2016-06-15 18:43:10 +12:00
|
|
|
if (InitializeQTML(0) != noErr) return;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
ComponentInstance ci =
|
|
|
|
OpenDefaultComponent(StandardCompressionType, StandardCompressionSubType);
|
|
|
|
QTAtomContainer settings;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
if (SCGetSettingsAsAtomContainer(ci, &settings) != noErr) assert(false);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
fromAtomsToProperties(settings, *this);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void TImageWriterMov::save(const TImageP &img) {
|
|
|
|
m_lwm->save(img, m_frameIndex);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void TLevelWriterMov::save(const TImageP &img, int frameIndex) {
|
|
|
|
m_firstFrame = std::min(frameIndex, m_firstFrame);
|
|
|
|
|
|
|
|
TRasterImageP image(img);
|
|
|
|
if (!image) throw TImageException(getFilePath(), "Unsupported image type");
|
|
|
|
|
|
|
|
int lx = image->getRaster()->getLx();
|
|
|
|
int ly = image->getRaster()->getLy();
|
|
|
|
|
|
|
|
int pixSize = image->getRaster()->getPixelSize();
|
|
|
|
if (pixSize != 4)
|
|
|
|
throw TImageException(getFilePath(), "Unsupported pixel type");
|
|
|
|
|
|
|
|
QMutexLocker sl(&m_mutex);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
if (!m_videoTrack) {
|
|
|
|
if (!m_properties) m_properties = new Tiio::MovWriterProperties();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
Tiio::MovWriterProperties *prop =
|
|
|
|
(Tiio::MovWriterProperties *)(m_properties);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
QTAtomContainer atoms;
|
|
|
|
QTNewAtomContainer(&atoms);
|
|
|
|
fromPropertiesToAtoms(*prop, atoms);
|
|
|
|
m_ci = OpenDefaultComponent(StandardCompressionType,
|
|
|
|
StandardCompressionSubType);
|
|
|
|
if (SCSetSettingsFromAtomContainer(m_ci, atoms) != noErr) {
|
|
|
|
CloseComponent(m_ci);
|
|
|
|
assert(!"cannot use that quickTime codec, use default");
|
|
|
|
m_ci = OpenDefaultComponent(StandardCompressionType,
|
|
|
|
StandardCompressionSubType);
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
QTDisposeAtomContainer(atoms);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
Rect frame;
|
|
|
|
QDErr err;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
if (QuickTimeStuff::instance()->getStatus() != noErr) {
|
|
|
|
m_IOError = QTNotInstalled;
|
|
|
|
throw TImageException(m_path, buildQTErrorString(m_IOError));
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
// First, set the movie's time scale to match a suitable multiple of
|
|
|
|
// m_frameRate.
|
|
|
|
// The timeScale will be used for both the movie and media.
|
|
|
|
TimeScale timeScale = ::frameRateToTimeScale(m_frameRate);
|
|
|
|
SetMovieTimeScale(m_movie, timeScale);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
m_videoTrack = NewMovieTrack(m_movie, FixRatio((short)lx, 1),
|
|
|
|
FixRatio((short)ly, 1), kNoVolume);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
if ((err = GetMoviesError() != noErr))
|
|
|
|
throw TImageException(getFilePath(), "can't create video track");
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
m_videoMedia = NewTrackMedia(m_videoTrack, VideoMediaType, timeScale, 0, 0);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
if ((err = GetMoviesError() != noErr))
|
|
|
|
throw TImageException(getFilePath(), "can't create video media");
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
frame.left = 0;
|
|
|
|
frame.top = 0;
|
|
|
|
frame.right = lx;
|
|
|
|
frame.bottom = ly;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
if ((err = NewGWorld(&(m_gworld), pixSize * 8, &frame, 0, 0, 0)) != noErr)
|
|
|
|
throw TImageException(getFilePath(), "can't create movie buffer");
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
LockPixels(m_gworld->portPixMap);
|
|
|
|
/*
|
|
|
|
if ((err = ImageCodecGetMaxCompressionSize(Ci, m_gworld->portPixMap, &frame, 0,
|
|
|
|
quality, codecType, anyCodec,
|
|
|
|
&max_compressed_size))!=noErr)
|
|
|
|
throw TImageException(getFilePath(), "can't
|
|
|
|
get max compression size");
|
|
|
|
*/
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
if ((err = MemError()) != noErr)
|
|
|
|
throw TImageException(getFilePath(), "can't allocate img handle");
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
m_pixmap = GetGWorldPixMap(m_gworld);
|
|
|
|
if (!LockPixels(m_pixmap))
|
|
|
|
throw TImageException(getFilePath(), "can't lock pixels");
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
m_buf = (PixelXRGB *)(*(m_pixmap))->baseAddr;
|
|
|
|
buf_lx = lx;
|
|
|
|
buf_ly = ly;
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
OSErr err = noErr;
|
|
|
|
if ((err = BeginMediaEdits(m_videoMedia)) != noErr)
|
|
|
|
throw TImageException(getFilePath(), "can't begin edit video media");
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
Rect frame;
|
|
|
|
ImageDescriptionHandle img_descr = 0;
|
|
|
|
Handle compressedData = 0;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
frame.left = 0;
|
|
|
|
frame.top = 0;
|
|
|
|
frame.right = lx;
|
|
|
|
frame.bottom = ly;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TRasterP ras = image->getRaster();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
copy(ras, m_buf, buf_lx, buf_ly);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
if ((err = SCCompressImage(m_ci, m_gworld->portPixMap, &frame, &img_descr,
|
|
|
|
&compressedData)) != noErr)
|
|
|
|
throw TImageException(getFilePath(), "can't compress image");
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
/*
|
|
|
|
if ((err = CompressImage(m_gworld->portPixMap,
|
|
|
|
&frame,
|
|
|
|
quality, codecType,
|
|
|
|
img_descr, compressed_data_ptr))!=noErr)
|
|
|
|
throw TImageException(getFilePath(), "can't compress image");
|
|
|
|
*/
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TimeValue sampleTime;
|
|
|
|
if ((err = AddMediaSample(m_videoMedia, compressedData, 0,
|
|
|
|
(*img_descr)->dataSize,
|
|
|
|
100, // 100 matches the length of 1 frame
|
|
|
|
(SampleDescriptionHandle)
|
|
|
|
img_descr, // in the movie/media's timeScale
|
|
|
|
1,
|
|
|
|
0, &sampleTime)) != noErr)
|
|
|
|
throw TImageException(getFilePath(), "can't add image to movie media");
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
if ((err = EndMediaEdits(m_videoMedia)) != noErr)
|
|
|
|
throw TImageException(getFilePath(), "can't end edit media");
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
DisposeHandle(compressedData);
|
|
|
|
DisposeHandle((Handle)img_descr);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
m_savedFrames.push_back(std::pair<int, TimeValue>(frameIndex, sampleTime));
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------
|
|
|
|
// TLevelWriterMov
|
|
|
|
//-----------------------------------------------------------
|
|
|
|
|
|
|
|
TLevelWriterMov::TLevelWriterMov(const TFilePath &path, TPropertyGroup *winfo)
|
2016-06-15 18:43:10 +12:00
|
|
|
: TLevelWriter(path, winfo)
|
|
|
|
, m_IOError(QTNoError)
|
|
|
|
, m_pixmap(0)
|
|
|
|
, m_gworld(0)
|
|
|
|
, m_videoMedia(0)
|
|
|
|
, m_soundMedia(0)
|
|
|
|
, m_videoTrack(0)
|
|
|
|
, m_soundTrack(0)
|
|
|
|
, m_movie(0)
|
|
|
|
, m_firstFrame((std::numeric_limits<int>::max)()) {
|
|
|
|
m_frameRate = 12.;
|
|
|
|
|
|
|
|
char *pStr = filePath2unichar(m_path);
|
|
|
|
QDErr err;
|
|
|
|
FSSpec fspec;
|
|
|
|
|
|
|
|
if ((err = NativePathNameToFSSpec(pStr, &fspec, kFullNativePath)) != noErr) {
|
|
|
|
delete[] pStr;
|
|
|
|
pStr = 0;
|
|
|
|
m_IOError = QTUnableToOpenFile;
|
|
|
|
throw TImageException(m_path, buildQTErrorString(m_IOError));
|
|
|
|
}
|
|
|
|
delete[] pStr;
|
|
|
|
pStr = 0;
|
|
|
|
|
|
|
|
if (err = CreateMovieFile(
|
|
|
|
&fspec, 'TVOD', smCurrentScript,
|
|
|
|
createMovieFileDeleteCurFile | createMovieFileDontCreateResFile,
|
|
|
|
&(m_refNum), &(m_movie)) != noErr) {
|
|
|
|
m_IOError = QTCantCreateFile;
|
|
|
|
throw TImageException(m_path, buildQTErrorString(m_IOError));
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
2016-06-15 18:43:10 +12:00
|
|
|
#define FailIf(cond, handler) \
|
|
|
|
if (cond) { \
|
|
|
|
DebugStr((ConstStr255Param) #cond " goto " #handler); \
|
|
|
|
goto handler; \
|
|
|
|
} else \
|
|
|
|
0
|
2016-03-19 06:57:51 +13:00
|
|
|
#else
|
2016-06-15 18:43:10 +12:00
|
|
|
#define FailIf(cond, handler) \
|
|
|
|
if (cond) { \
|
|
|
|
goto handler; \
|
|
|
|
} else \
|
|
|
|
0
|
2016-03-19 06:57:51 +13:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
2016-06-15 18:43:10 +12:00
|
|
|
#define FailWithAction(cond, action, handler) \
|
|
|
|
if (cond) { \
|
|
|
|
DebugStr((ConstStr255Param) #cond " goto " #handler); \
|
|
|
|
{ action; } \
|
|
|
|
goto handler; \
|
|
|
|
} else \
|
|
|
|
0
|
2016-03-19 06:57:51 +13:00
|
|
|
#else
|
2016-06-15 18:43:10 +12:00
|
|
|
#define FailWithAction(cond, action, handler) \
|
|
|
|
if (cond) { \
|
|
|
|
{ action; } \
|
|
|
|
goto handler; \
|
|
|
|
} else \
|
|
|
|
0
|
2016-03-19 06:57:51 +13:00
|
|
|
#endif
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void TLevelWriterMov::saveSoundTrack(TSoundTrack *st) {
|
|
|
|
OSErr myErr = noErr;
|
|
|
|
|
|
|
|
if (!st) throw TException("null reference to soundtrack");
|
|
|
|
|
|
|
|
if (st->getBitPerSample() != 16)
|
|
|
|
throw TImageException(m_path, "Only 16 bits per sample is supported");
|
|
|
|
|
|
|
|
if (m_soundTrack == 0) {
|
|
|
|
m_soundTrack = NewMovieTrack(m_movie, 0, 0, kFullVolume);
|
|
|
|
myErr = GetMoviesError();
|
|
|
|
|
|
|
|
FailIf(myErr != noErr, CompressErr);
|
|
|
|
|
|
|
|
m_soundMedia =
|
|
|
|
NewTrackMedia(m_soundTrack, SoundMediaType, st->getSampleRate(), NULL,
|
|
|
|
0); // track->rate >> 16
|
|
|
|
myErr = GetMoviesError();
|
|
|
|
|
|
|
|
FailIf(myErr != noErr, Exit);
|
|
|
|
}
|
|
|
|
|
|
|
|
SoundDescriptionV1Handle mySampleDesc;
|
|
|
|
Handle myDestHandle;
|
|
|
|
SoundComponentData sourceInfo;
|
|
|
|
SoundComponentData destInfo;
|
|
|
|
SoundConverter converter;
|
|
|
|
CompressionInfo compressionInfo;
|
|
|
|
|
|
|
|
myDestHandle = NewHandle(0);
|
|
|
|
FailWithAction(myDestHandle == NULL, myErr = MemError(), NoDest);
|
|
|
|
|
|
|
|
*myDestHandle = (char *)st->getRawData();
|
|
|
|
|
|
|
|
// start a media editing session
|
|
|
|
myErr = BeginMediaEdits(m_soundMedia);
|
|
|
|
FailIf(myErr != noErr, Exit);
|
|
|
|
|
|
|
|
sourceInfo.flags = 0x0;
|
|
|
|
sourceInfo.format = kSoundNotCompressed;
|
|
|
|
sourceInfo.numChannels = st->getChannelCount();
|
|
|
|
sourceInfo.sampleSize = st->getBitPerSample();
|
|
|
|
sourceInfo.sampleRate = st->getSampleRate();
|
|
|
|
sourceInfo.sampleCount = st->getSampleCount();
|
|
|
|
sourceInfo.buffer = (unsigned char *)st->getRawData();
|
|
|
|
sourceInfo.reserved = 0x0;
|
|
|
|
|
|
|
|
destInfo.flags = kNoSampleRateConversion | kNoSampleSizeConversion |
|
|
|
|
kNoSampleFormatConversion | kNoChannelConversion |
|
|
|
|
kNoDecompression | kNoVolumeConversion |
|
|
|
|
kNoRealtimeProcessing;
|
|
|
|
|
|
|
|
destInfo.format = k16BitNativeEndianFormat;
|
|
|
|
destInfo.numChannels = st->getChannelCount();
|
|
|
|
destInfo.sampleSize = st->getBitPerSample();
|
|
|
|
destInfo.sampleRate = st->getSampleRate();
|
|
|
|
destInfo.sampleCount = st->getSampleCount();
|
|
|
|
destInfo.buffer = (unsigned char *)st->getRawData();
|
|
|
|
destInfo.reserved = 0x0;
|
|
|
|
|
|
|
|
SoundConverterOpen(&sourceInfo, &destInfo, &converter);
|
|
|
|
|
|
|
|
myErr =
|
|
|
|
SoundConverterGetInfo(converter, siCompressionFactor, &compressionInfo);
|
|
|
|
|
|
|
|
myErr =
|
|
|
|
SoundConverterGetInfo(converter, siCompressionFactor, &compressionInfo);
|
|
|
|
myErr = GetCompressionInfo(fixedCompression, sourceInfo.format,
|
|
|
|
sourceInfo.numChannels, sourceInfo.sampleSize,
|
|
|
|
&compressionInfo);
|
|
|
|
FailIf(myErr != noErr, ConverterErr);
|
|
|
|
|
|
|
|
compressionInfo.bytesPerFrame =
|
|
|
|
compressionInfo.bytesPerPacket * destInfo.numChannels;
|
|
|
|
|
|
|
|
//////////
|
|
|
|
//
|
|
|
|
// create a sound sample description
|
|
|
|
//
|
|
|
|
//////////
|
|
|
|
|
|
|
|
// use the SoundDescription format 1 because it adds fields for data size
|
|
|
|
// information
|
|
|
|
// and is required by AddSoundDescriptionExtension if an extension is required
|
|
|
|
// for the compression format
|
|
|
|
|
|
|
|
mySampleDesc =
|
|
|
|
(SoundDescriptionV1Handle)NewHandleClear(sizeof(SoundDescriptionV1));
|
|
|
|
FailWithAction(myErr != noErr, myErr = MemError(), Exit);
|
|
|
|
|
|
|
|
(**mySampleDesc).desc.descSize = sizeof(SoundDescriptionV1);
|
|
|
|
(**mySampleDesc).desc.dataFormat = destInfo.format;
|
|
|
|
(**mySampleDesc).desc.resvd1 = 0;
|
|
|
|
(**mySampleDesc).desc.resvd2 = 0;
|
|
|
|
(**mySampleDesc).desc.dataRefIndex = 1;
|
|
|
|
(**mySampleDesc).desc.version = 1;
|
|
|
|
(**mySampleDesc).desc.revlevel = 0;
|
|
|
|
(**mySampleDesc).desc.vendor = 0;
|
|
|
|
(**mySampleDesc).desc.numChannels = destInfo.numChannels;
|
|
|
|
(**mySampleDesc).desc.sampleSize = destInfo.sampleSize;
|
|
|
|
(**mySampleDesc).desc.compressionID = 0;
|
|
|
|
(**mySampleDesc).desc.packetSize = 0;
|
|
|
|
(**mySampleDesc).desc.sampleRate = st->getSampleRate() << 16;
|
|
|
|
(**mySampleDesc).samplesPerPacket = compressionInfo.samplesPerPacket;
|
|
|
|
(**mySampleDesc).bytesPerPacket = compressionInfo.bytesPerPacket;
|
|
|
|
(**mySampleDesc).bytesPerFrame = compressionInfo.bytesPerFrame;
|
|
|
|
(**mySampleDesc).bytesPerSample = compressionInfo.bytesPerSample;
|
|
|
|
|
|
|
|
//////////
|
|
|
|
//
|
|
|
|
// add samples to the media
|
|
|
|
//
|
|
|
|
//////////
|
|
|
|
|
|
|
|
myErr = AddMediaSample(
|
|
|
|
m_soundMedia, myDestHandle, 0,
|
|
|
|
destInfo.sampleCount * compressionInfo.bytesPerFrame, 1,
|
|
|
|
(SampleDescriptionHandle)mySampleDesc,
|
|
|
|
destInfo.sampleCount * compressionInfo.samplesPerPacket, 0, NULL);
|
|
|
|
FailIf(myErr != noErr, MediaErr);
|
|
|
|
|
|
|
|
myErr = EndMediaEdits(m_soundMedia);
|
|
|
|
FailIf(myErr != noErr, MediaErr);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
// NOTE: Sound media is inserted into the movie track only at destruction
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
ConverterErr: // Multiple bailout labels just to
|
|
|
|
NoDest: // separate debugging strings, it seems.
|
|
|
|
CompressErr: //
|
|
|
|
Exit: // Should be done better...
|
|
|
|
MediaErr: //
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
if (mySampleDesc != NULL) DisposeHandle((Handle)mySampleDesc);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
if (converter) SoundConverterClose(converter);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
if (myErr != noErr) throw TImageException(m_path, "error saving audio track");
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TLevelWriterMov::~TLevelWriterMov() {
|
|
|
|
if (m_pixmap) UnlockPixels(m_pixmap);
|
|
|
|
if (m_gworld && m_gworld->portPixMap) UnlockPixels(m_gworld->portPixMap);
|
|
|
|
|
|
|
|
if (m_gworld) DisposeGWorld(m_gworld);
|
|
|
|
if (m_ci) CloseComponent(m_ci);
|
|
|
|
|
|
|
|
QDErr err;
|
|
|
|
OSStatus mderr;
|
|
|
|
|
|
|
|
if (m_videoTrack) {
|
|
|
|
// Insert the saved Frames into the track.
|
|
|
|
|
|
|
|
// NOTE: Holes in the frames sequence will be intended as still frames,
|
|
|
|
// rather than left blank.
|
|
|
|
// I'm quite unsure whether this behavior is actually useful - or used
|
|
|
|
// at all.
|
|
|
|
// In particular, the last frame is an exception, and does NOT drag to
|
|
|
|
// the end of the
|
|
|
|
// movie (see below). I think it's not used - frames are consecutive
|
|
|
|
// AFAIK.
|
|
|
|
|
|
|
|
TimeValue movieTimeScale = GetMovieTimeScale(m_movie);
|
|
|
|
int savedFramesSize = (int)m_savedFrames.size() - 1;
|
|
|
|
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < savedFramesSize; ++i) {
|
|
|
|
TimeValue mediaPosition = m_savedFrames[i].second;
|
|
|
|
TimeValue trackPosition =
|
|
|
|
((m_savedFrames[i].first - m_firstFrame) * movieTimeScale) /
|
|
|
|
m_frameRate;
|
|
|
|
|
|
|
|
TimeValue duration = m_savedFrames[i + 1].first - m_savedFrames[i].first;
|
|
|
|
Fixed ratio = tround(fixed1 / (double)duration);
|
|
|
|
|
|
|
|
if ((err = InsertMediaIntoTrack(m_videoTrack, trackPosition,
|
|
|
|
mediaPosition, 100, ratio)) != noErr)
|
|
|
|
throw TImageException(getFilePath(), "can't insert media into track");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (savedFramesSize >= 0) {
|
|
|
|
TimeValue mediaPosition = m_savedFrames[i].second;
|
|
|
|
TimeValue trackPosition =
|
|
|
|
((m_savedFrames[i].first - m_firstFrame) * movieTimeScale) /
|
|
|
|
m_frameRate;
|
|
|
|
|
|
|
|
// The last frame has duration 1 (frame):
|
|
|
|
// duration = 1 => ratio = fixed1
|
|
|
|
|
|
|
|
if ((err = InsertMediaIntoTrack(m_videoTrack, trackPosition,
|
|
|
|
mediaPosition, 100, fixed1)) != noErr)
|
|
|
|
throw TImageException(getFilePath(), "can't insert media into track");
|
|
|
|
}
|
|
|
|
|
|
|
|
QTMetaDataRef metaDataRef;
|
|
|
|
if ((mderr = QTCopyMovieMetaData(m_movie, &metaDataRef)) != noErr)
|
|
|
|
throw TImageException(getFilePath(),
|
|
|
|
"can't access metadata informations");
|
|
|
|
|
|
|
|
if ((mderr = QTMetaDataAddItem(
|
|
|
|
metaDataRef, kQTMetaDataStorageFormatUserData,
|
|
|
|
kQTMetaDataKeyFormatUserData, (const UInt8 *)firstFrameKey.c_str(),
|
|
|
|
firstFrameKeySize, (const UInt8 *)(&m_firstFrame), sizeof(int),
|
|
|
|
kQTMetaDataTypeUnsignedIntegerBE, 0)) != noErr)
|
|
|
|
throw TImageException(getFilePath(),
|
|
|
|
"can't insert metadata informations");
|
|
|
|
|
|
|
|
QTMetaDataRelease(metaDataRef);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_soundTrack) {
|
|
|
|
if (0 != (err = InsertMediaIntoTrack(
|
|
|
|
m_soundTrack, 0, 0, GetMediaDuration(m_soundMedia), fixed1)))
|
|
|
|
throw TImageException(getFilePath(), "can't insert sound into track");
|
|
|
|
}
|
|
|
|
|
|
|
|
short resId = movieInDataForkResID;
|
|
|
|
if (m_movie) {
|
|
|
|
if ((err = AddMovieResource(m_movie, m_refNum, &resId, 0)) !=
|
|
|
|
noErr) // Why no thrown exception here?
|
|
|
|
{
|
|
|
|
} // throw TImageException(getFilePath(), "Can't add resource"); //
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_videoMedia) // And anyway, how exceptions
|
|
|
|
DisposeTrackMedia(m_videoMedia); // deal with absence of corresponding
|
|
|
|
if (m_videoTrack) // disposals?
|
|
|
|
DisposeMovieTrack(m_videoTrack); // I guess se should use RAII here... -.-'
|
|
|
|
if (m_soundMedia) DisposeTrackMedia(m_soundMedia);
|
|
|
|
|
|
|
|
if (m_refNum) CloseMovieFile(m_refNum);
|
|
|
|
|
|
|
|
DisposeMovie(m_movie);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TImageWriterP TLevelWriterMov::getFrameWriter(TFrameId fid) {
|
|
|
|
if (m_IOError) throw TImageException(m_path, buildQTErrorString(m_IOError));
|
|
|
|
if (fid.getLetter() != 0) return TImageWriterP(0);
|
|
|
|
int index = fid.getNumber() - 1;
|
|
|
|
|
|
|
|
TImageWriterMov *iwm = new TImageWriterMov(m_path, index, this);
|
|
|
|
return TImageWriterP(iwm);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------
|
|
|
|
|
|
|
|
TLevelReaderMov::TLevelReaderMov(const TFilePath &path)
|
2016-06-15 18:43:10 +12:00
|
|
|
: TLevelReader(path)
|
|
|
|
, m_IOError(QTNoError)
|
|
|
|
, m_track(0)
|
|
|
|
, m_movie(0)
|
|
|
|
, m_depth(0)
|
|
|
|
, m_readAsToonzOutput(false)
|
|
|
|
, m_yMirror(true)
|
|
|
|
, m_loadTimecode(false) {
|
|
|
|
FSSpec fspec;
|
|
|
|
QDErr err;
|
|
|
|
Boolean dataRefWasChanged;
|
|
|
|
|
|
|
|
if (QuickTimeStuff::instance()->getStatus() != noErr) {
|
|
|
|
m_IOError = QTNotInstalled;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *pStr = filePath2unichar(m_path);
|
|
|
|
|
|
|
|
if ((err = NativePathNameToFSSpec(pStr, &fspec, kFullNativePath)) != noErr) {
|
|
|
|
delete[] pStr;
|
|
|
|
pStr = 0;
|
|
|
|
throw TImageException(path, "can't open file");
|
|
|
|
}
|
|
|
|
delete[] pStr;
|
|
|
|
pStr = 0;
|
|
|
|
|
|
|
|
if ((err = OpenMovieFile(&fspec, &m_refNum, fsRdPerm))) {
|
|
|
|
m_IOError = QTUnableToOpenFile;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
short resId = 0;
|
|
|
|
Str255 name;
|
|
|
|
err = NewMovieFromFile(&m_movie, m_refNum, &resId, name, fsRdPerm,
|
|
|
|
&dataRefWasChanged);
|
|
|
|
|
|
|
|
int numTracks = GetMovieTrackCount(m_movie);
|
|
|
|
if (numTracks < 1) {
|
|
|
|
m_IOError = QTUnableToOpenFile;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(numTracks == 1 || numTracks == 2);
|
|
|
|
|
|
|
|
m_track =
|
|
|
|
GetMovieIndTrackType(m_movie, 1, VideoMediaType, movieTrackMediaType);
|
|
|
|
|
|
|
|
ImageDescriptionHandle imageH;
|
|
|
|
imageH = (ImageDescriptionHandle)NewHandleClear(sizeof(ImageDescription));
|
|
|
|
|
|
|
|
TINT32 index = 1;
|
|
|
|
Media theMedia = GetTrackMedia(m_track);
|
|
|
|
|
|
|
|
GetMediaSampleDescription(theMedia, index, (SampleDescriptionHandle)imageH);
|
|
|
|
ImageDescriptionPtr imagePtr = *imageH;
|
|
|
|
|
|
|
|
if ((imagePtr->cType >> 16) == 0x4458 /*'DX'*/ &&
|
|
|
|
path.getType() == "avi") // DIVX - compressed, QT is unable to read it.
|
|
|
|
{ // Done externally with the... AVI reader o_o.
|
|
|
|
m_IOError = QTUnableToDoMovieTask;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Retrieve the timecode media handler
|
|
|
|
{
|
|
|
|
Track tcTrack = GetMovieIndTrackType(m_movie, 1, TimeCodeMediaType,
|
|
|
|
movieTrackMediaType);
|
|
|
|
Media tcMedia = GetTrackMedia(tcTrack);
|
|
|
|
m_timecodeHandler = GetMediaHandler(tcMedia);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_lx = imagePtr->width;
|
|
|
|
m_ly = imagePtr->height;
|
|
|
|
m_depth = imagePtr->depth;
|
|
|
|
|
|
|
|
m_info = new TImageInfo();
|
|
|
|
|
|
|
|
m_info->m_lx = m_lx;
|
|
|
|
m_info->m_ly = m_ly;
|
|
|
|
m_info->m_frameRate = GetMediaTimeScale(theMedia) /
|
|
|
|
100.0; // REMOVE THIS! Not all movs have this
|
|
|
|
// kind of format - only those from Toonz...
|
|
|
|
Tiio::MovWriterProperties *prop = new Tiio::MovWriterProperties();
|
|
|
|
m_info->m_properties = prop;
|
|
|
|
|
|
|
|
DisposeHandle((Handle)imageH);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TLevelReaderMov::~TLevelReaderMov() {
|
|
|
|
StopMovie(m_movie);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
if (m_refNum) CloseMovieFile(m_refNum);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
if (m_movie) DisposeMovie(m_movie);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void TLevelReaderMov::loadedTimecode(UCHAR &hh, UCHAR &mm, UCHAR &ss,
|
|
|
|
UCHAR &ff) {
|
|
|
|
hh = m_hh, mm = m_mm, ss = m_ss, ff = m_ff;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void TLevelReaderMov::setYMirror(bool enabled) { m_yMirror = enabled; }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void TLevelReaderMov::setLoadTimecode(bool enabled) {
|
|
|
|
m_loadTimecode = enabled;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void TLevelReaderMov::enableRandomAccessRead(bool enable) {
|
|
|
|
m_readAsToonzOutput = enable;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------
|
|
|
|
// TImageReaderMov
|
|
|
|
//-----------------------------------------------------------
|
|
|
|
|
2016-06-29 18:17:12 +12:00
|
|
|
class TImageReaderMov final : public TImageReader {
|
2016-06-15 18:43:10 +12:00
|
|
|
TLevelReaderMov *m_lrm;
|
|
|
|
TImageInfo *m_info;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
int m_frameIndex;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
TImageReaderMov(const TFilePath &, int frameIndex, TLevelReaderMov *,
|
|
|
|
TImageInfo *);
|
|
|
|
~TImageReaderMov() { m_lrm->release(); }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
TImageP load() override;
|
2016-06-15 18:43:10 +12:00
|
|
|
void load(const TRasterP &rasP, const TPoint &pos = TPoint(0, 0),
|
|
|
|
int shrinkX = 1, int shrinkY = 1);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TDimension getSize() const { return m_lrm->getSize(); }
|
|
|
|
TRect getBBox() const { return m_lrm->getBBox(); }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
const TImageInfo *getImageInfo() const override { return m_info; }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
private:
|
2016-06-15 18:43:10 +12:00
|
|
|
// Not copyable
|
|
|
|
TImageReaderMov(const TImageReaderMov &);
|
|
|
|
TImageReaderMov &operator=(const TImageReaderMov &);
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
//------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TImageReaderMov::TImageReaderMov(const TFilePath &path, int frameIndex,
|
|
|
|
TLevelReaderMov *lrm, TImageInfo *info)
|
|
|
|
: TImageReader(path), m_lrm(lrm), m_frameIndex(frameIndex), m_info(info) {
|
|
|
|
m_lrm->addRef();
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TLevelP TLevelReaderMov::loadInfo() {
|
|
|
|
if (m_readAsToonzOutput) // Mov files written with Toonz support special
|
|
|
|
return loadToonzOutputFormatInfo(); // metadata atoms - separate procedure
|
|
|
|
|
|
|
|
// Level is NOT a recognized mov from Toonz. Just read each movie's
|
|
|
|
// interesting image as a consecutive
|
|
|
|
// level frame.
|
|
|
|
|
|
|
|
TLevelP level;
|
|
|
|
if (m_IOError != QTNoError)
|
|
|
|
throw TImageException(m_path, buildQTErrorString(m_IOError));
|
|
|
|
|
|
|
|
OSType mediaType = VisualMediaCharacteristic;
|
|
|
|
TimeValue nextTime, currentTime;
|
|
|
|
currentTime = 0;
|
|
|
|
nextTime = 0;
|
|
|
|
|
|
|
|
int f = 0; // 0 is the first frame index
|
|
|
|
|
|
|
|
// io vorrei fare '|', ma sul manuale c'e' scritto '+'
|
|
|
|
GetMovieNextInterestingTime(m_movie, nextTimeMediaSample + nextTimeEdgeOK, 1,
|
|
|
|
&mediaType, currentTime, 0, &nextTime, 0);
|
|
|
|
|
|
|
|
if (nextTime != -1) {
|
|
|
|
TFrameId frame(f + 1);
|
|
|
|
level->setFrame(frame, TImageP());
|
|
|
|
currentTimes[f] = nextTime;
|
|
|
|
++f;
|
|
|
|
}
|
|
|
|
|
|
|
|
currentTime = nextTime;
|
|
|
|
while (nextTime != -1) {
|
|
|
|
GetMovieNextInterestingTime(m_movie, nextTimeMediaSample, 1, &mediaType,
|
|
|
|
currentTime, 0, &nextTime, 0);
|
|
|
|
if (nextTime != -1) {
|
|
|
|
TFrameId frame(f + 1);
|
|
|
|
level->setFrame(frame, TImageP());
|
|
|
|
currentTimes[f] = nextTime;
|
|
|
|
++f;
|
|
|
|
}
|
|
|
|
|
|
|
|
currentTime = nextTime;
|
|
|
|
}
|
|
|
|
return level;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TLevelP TLevelReaderMov::loadToonzOutputFormatInfo() {
|
|
|
|
TLevelP level;
|
|
|
|
if (m_IOError != QTNoError)
|
|
|
|
throw TImageException(m_path, buildQTErrorString(m_IOError));
|
|
|
|
|
|
|
|
OSStatus mderr;
|
|
|
|
|
|
|
|
// Retrieve the first frame of movie. This info has been put in a metadata
|
|
|
|
// atom.
|
|
|
|
QTMetaDataRef metaDataRef;
|
|
|
|
if ((mderr = QTCopyMovieMetaData(m_movie, &metaDataRef)) != noErr)
|
|
|
|
throw TImageException(m_path, "can't access metadata informations");
|
|
|
|
|
|
|
|
QTMetaDataItem firstFrameItem;
|
|
|
|
|
|
|
|
// Find the metadata atom
|
|
|
|
mderr = QTMetaDataGetNextItem(
|
|
|
|
metaDataRef, kQTMetaDataStorageFormatUserData,
|
|
|
|
kQTMetaDataItemUninitialized, kQTMetaDataKeyFormatUserData,
|
|
|
|
(const UInt8 *)firstFrameKey.c_str(), firstFrameKeySize, &firstFrameItem);
|
|
|
|
|
|
|
|
// Try to read the value. If the atom was not found, just assume firstFrame =
|
|
|
|
// 0.
|
|
|
|
int firstFrame = 0;
|
|
|
|
if (mderr == noErr) {
|
|
|
|
// The atom was found. Then, retrieve the value
|
|
|
|
if ((mderr = QTMetaDataGetItemValue(metaDataRef, firstFrameItem,
|
|
|
|
(UInt8 *)(&firstFrame), sizeof(int),
|
|
|
|
0) != noErr))
|
|
|
|
throw TImageException(m_path, "can't read metadata informations");
|
|
|
|
}
|
|
|
|
|
|
|
|
mderr = 0;
|
|
|
|
|
|
|
|
QTMetaDataRelease(metaDataRef);
|
|
|
|
|
|
|
|
OSType mediaType = VisualMediaCharacteristic;
|
|
|
|
TimeValue nextTime = 0, currentTime = 0;
|
|
|
|
|
|
|
|
TimeValue movieDuration = GetMovieDuration(m_movie);
|
|
|
|
|
|
|
|
std::vector<TimeValue> interestingTimeValues;
|
|
|
|
|
|
|
|
// io vorrei fare '|', ma sul manuale c'e' scritto '+'
|
|
|
|
GetMovieNextInterestingTime(m_movie, nextTimeMediaSample + nextTimeEdgeOK, 1,
|
|
|
|
&mediaType, currentTime, 0, &nextTime, 0);
|
|
|
|
if (nextTime != -1) {
|
|
|
|
interestingTimeValues.push_back(nextTime);
|
|
|
|
currentTime = nextTime;
|
|
|
|
}
|
|
|
|
while (nextTime != -1) {
|
|
|
|
GetMovieNextInterestingTime(m_movie, nextTimeMediaSample, 1, &mediaType,
|
|
|
|
currentTime, 0, &nextTime, 0);
|
|
|
|
if (nextTime != -1) {
|
|
|
|
interestingTimeValues.push_back(nextTime);
|
|
|
|
currentTime = nextTime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentTime != -1) {
|
|
|
|
double frameRate = m_info->m_frameRate;
|
|
|
|
TimeScale movieTimeScale = GetMovieTimeScale(m_movie);
|
|
|
|
int firstFrameTimeValue = movieTimeScale * firstFrame;
|
|
|
|
|
|
|
|
std::vector<TimeValue>::iterator it;
|
|
|
|
for (it = interestingTimeValues.begin(); it != interestingTimeValues.end();
|
|
|
|
++it) {
|
|
|
|
int frame =
|
|
|
|
firstFrame +
|
|
|
|
tround((*it * frameRate) /
|
|
|
|
(double)movieTimeScale); // (Daniele) There was a ceil here,
|
|
|
|
TFrameId frameId(frame + 1); // before. But I honestly don't remember
|
|
|
|
level->setFrame(frameId,
|
|
|
|
TImageP()); // WHY I placed it there. Round seems more
|
|
|
|
currentTimes[frame] = *it; // appropriate...
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return level;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TImageP TImageReaderMov::load() {
|
|
|
|
TRasterPT<TPixelRGBM32> ret(m_lrm->getSize());
|
|
|
|
m_lrm->load(ret, m_frameIndex, TPointI(), 1, 1);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
return TRasterImageP(ret);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void TImageReaderMov::load(const TRasterP &rasP, const TPoint &pos, int shrinkX,
|
|
|
|
int shrinkY) {
|
|
|
|
if ((shrinkX != 1) || (shrinkY != 1) || (pos != TPoint(0, 0)))
|
|
|
|
TImageReader::load(rasP, pos, shrinkX, shrinkY);
|
|
|
|
else
|
|
|
|
m_lrm->load(rasP, m_frameIndex, pos, shrinkX, shrinkY);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
inline void setMatteAndYMirror(const TRaster32P &ras) {
|
|
|
|
ras->lock();
|
|
|
|
TPixel32 *upRow = ras->pixels();
|
|
|
|
TPixel32 *dwRow = ras->pixels(ras->getLy() - 1);
|
2016-06-20 14:23:05 +12:00
|
|
|
int hLy = (int)(ras->getLy() / 2. + 0.5); // piccola pessimizzazione...
|
|
|
|
int wrap = ras->getWrap();
|
|
|
|
int lx = ras->getLx();
|
2016-06-15 18:43:10 +12:00
|
|
|
TPixel32 *upPix = 0;
|
|
|
|
|
|
|
|
TPixel32 *lastPix = ras->pixels(hLy);
|
|
|
|
while (upPix < lastPix) {
|
|
|
|
upPix = upRow;
|
|
|
|
TPixel32 *dwPix = dwRow;
|
|
|
|
TPixel32 *endPix = upPix + lx;
|
|
|
|
while (upPix < endPix) {
|
|
|
|
TPixel32 tmpPix(upPix->r, upPix->g, upPix->b, 0xff);
|
|
|
|
*upPix = *dwPix;
|
|
|
|
upPix->m = 0xff;
|
|
|
|
*dwPix = tmpPix;
|
|
|
|
++upPix;
|
|
|
|
++dwPix;
|
|
|
|
}
|
|
|
|
upRow += wrap;
|
|
|
|
dwRow -= wrap;
|
|
|
|
}
|
|
|
|
ras->unlock();
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void TLevelReaderMov::load(const TRasterP &rasP, int frameIndex,
|
|
|
|
const TPoint &pos, int shrinkX, int shrinkY) {
|
|
|
|
GWorldPtr offscreenGWorld = 0;
|
|
|
|
{
|
|
|
|
QMutexLocker sl(&m_mutex);
|
|
|
|
if (m_IOError != QTNoError)
|
|
|
|
throw TImageException(m_path, buildQTErrorString(m_IOError));
|
|
|
|
|
|
|
|
TRaster32P ras = rasP;
|
|
|
|
|
|
|
|
Rect rect;
|
|
|
|
rect.right = pos.x + ras->getLx();
|
|
|
|
rect.left = pos.x;
|
|
|
|
rect.bottom = pos.y + ras->getLy();
|
|
|
|
rect.top = pos.y;
|
|
|
|
|
|
|
|
OSErr err;
|
|
|
|
ras->lock();
|
|
|
|
err = QTNewGWorldFromPtr(&offscreenGWorld, k32BGRAPixelFormat, &rect, 0, 0,
|
|
|
|
0, ras->getRawData(), ras->getWrap() * 4);
|
|
|
|
|
|
|
|
if (err != noErr) {
|
|
|
|
m_IOError = QTUnableToCreateResource;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetMovieBox(m_movie, &rect);
|
|
|
|
err = GetMoviesError();
|
|
|
|
if (err != noErr) {
|
|
|
|
m_IOError = QTUnableToSetMovieBox;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetMovieGWorld(m_movie, offscreenGWorld, GetGWorldDevice(offscreenGWorld));
|
|
|
|
err = GetMoviesError();
|
|
|
|
if (err != noErr) {
|
|
|
|
m_IOError = QTUnableToSetMovieGWorld;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentTimes.empty()) loadInfo();
|
|
|
|
|
|
|
|
std::map<int, TimeValue>::iterator it = currentTimes.find(frameIndex);
|
|
|
|
if (it == currentTimes.end()) goto error;
|
|
|
|
|
|
|
|
TimeValue currentTime = it->second;
|
|
|
|
SetMovieTimeValue(m_movie, currentTime);
|
|
|
|
|
|
|
|
err = GetMoviesError();
|
|
|
|
if (err != noErr) {
|
|
|
|
m_IOError = QTUnableToSetTimeValue;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = UpdateMovie(m_movie);
|
|
|
|
if (err != noErr) {
|
|
|
|
m_IOError = QTUnableToUpdateMovie;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
MoviesTask(m_movie, 0);
|
|
|
|
err = GetMoviesError();
|
|
|
|
if (err != noErr) {
|
|
|
|
m_IOError = QTUnableToDoMovieTask;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
DisposeGWorld(offscreenGWorld);
|
|
|
|
ras->unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_yMirror) {
|
|
|
|
if (m_depth != 32)
|
|
|
|
setMatteAndYMirror(rasP);
|
|
|
|
else
|
|
|
|
rasP->yMirror();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_loadTimecode) {
|
|
|
|
// Also build current Timecode
|
|
|
|
TimeCodeRecord tc;
|
|
|
|
HandlerError err = TCGetCurrentTimeCode(m_timecodeHandler, 0, 0, &tc, 0);
|
|
|
|
|
|
|
|
m_hh = tc.t.hours;
|
|
|
|
m_mm = tc.t.minutes;
|
|
|
|
m_ss = tc.t.seconds;
|
|
|
|
m_ff = tc.t.frames;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
2016-03-19 06:57:51 +13:00
|
|
|
error:
|
2016-06-15 18:43:10 +12:00
|
|
|
rasP->unlock();
|
|
|
|
if (offscreenGWorld) DisposeGWorld(offscreenGWorld);
|
|
|
|
throw TImageException(m_path, buildQTErrorString(m_IOError));
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void TLevelReaderMov::timecode(int frameIndex, UCHAR &hh, UCHAR &mm, UCHAR &ss,
|
|
|
|
UCHAR &ff) {
|
|
|
|
hh = mm = ss = ff = 0xff;
|
|
|
|
if (!m_timecodeHandler) return;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
QMutexLocker sl(&m_mutex);
|
|
|
|
{
|
|
|
|
if (m_IOError != QTNoError) goto error;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
if (currentTimes.empty()) loadInfo();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
std::map<int, TimeValue>::iterator it = currentTimes.find(frameIndex);
|
|
|
|
if (it == currentTimes.end()) goto error;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TimeValue currentTime = it->second;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TimeCodeRecord tc;
|
|
|
|
HandlerError err =
|
|
|
|
TCGetTimeCodeAtTime(m_timecodeHandler, currentTime, 0, 0, &tc, 0);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
hh = tc.t.hours;
|
|
|
|
mm = tc.t.minutes;
|
|
|
|
ss = tc.t.seconds;
|
|
|
|
ff = tc.t.frames;
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
return;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
error:
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
throw TImageException(m_path, buildQTErrorString(m_IOError));
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TImageReaderP TLevelReaderMov::getFrameReader(TFrameId fid) {
|
|
|
|
if (m_IOError != QTNoError)
|
|
|
|
throw TImageException(m_path, buildQTErrorString(m_IOError));
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
if (fid.getLetter() != 0) return TImageReaderP(0);
|
|
|
|
int index = fid.getNumber() - 1;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TImageReaderMov *irm = new TImageReaderMov(m_path, index, this, m_info);
|
|
|
|
return TImageReaderP(irm);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TLevelReader *TLevelReaderMov::create(const TFilePath &f) {
|
|
|
|
TLevelReaderMov *reader = new TLevelReaderMov(f);
|
|
|
|
if (reader->m_IOError != QTNoError && f.getType() == "avi") {
|
|
|
|
delete reader;
|
|
|
|
return new TLevelReaderAvi(f);
|
|
|
|
} else
|
|
|
|
return reader;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
// You can use the SCSetInfo function with the scSettingsStateType selector to
|
|
|
|
// retrieve a handle
|
|
|
|
// containing the current compression settings; this might be useful if you
|
|
|
|
// were allowing the user
|
|
|
|
// to compress a series of images and wanted to preserve the user's settings
|
|
|
|
// from one image to the
|
|
|
|
// next (instead of reverting to the defaults for every image). Note, however,
|
|
|
|
// that the data in
|
|
|
|
// that handle is byte-ordered according to the platform the code is running
|
|
|
|
// on. As a result, you
|
|
|
|
// should not store that data in a file and expect that file to be valid on
|
|
|
|
// other platforms. To
|
|
|
|
// get a handle of data in a platform-independent format, use the function
|
|
|
|
// SCGetSettingsAsAtomContainer
|
|
|
|
// (introduced in QuickTime 3); to restore the settings in that handle, use the
|
|
|
|
// related function
|
2016-03-19 06:57:51 +13:00
|
|
|
// SCSetSettingsAsAtomContainer.
|
|
|
|
//
|
|
|
|
|
|
|
|
#endif
|