|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "casmfileinfo.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
namespace
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//==============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include <stdlib.h></stdlib.h>
|
|
Toshihiro Shimizu |
890ddd |
#include <stdio.h></stdio.h>
|
|
Toshihiro Shimizu |
890ddd |
#include <string.h></string.h>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*---------------------------------------------------------------------------*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define SKIP_BLANKS(s) \
|
|
Toshihiro Shimizu |
890ddd |
{ \
|
|
Toshihiro Shimizu |
890ddd |
while (*s && (*s == ' ' || *s == '\t') && *s != 10 && *s != 13) \
|
|
Toshihiro Shimizu |
890ddd |
s++; \
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define GET_WORD(s, p) \
|
|
Toshihiro Shimizu |
890ddd |
{ \
|
|
Toshihiro Shimizu |
890ddd |
while (*s && *s != ' ' && *s != '\t' && *s != 10 && *s != 13) \
|
|
Toshihiro Shimizu |
890ddd |
*(p++) = *(s++); \
|
|
Toshihiro Shimizu |
890ddd |
*p = '\0'; \
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define SKIP_WORD(s) \
|
|
Toshihiro Shimizu |
890ddd |
{ \
|
|
Toshihiro Shimizu |
890ddd |
while (*s && *s != ' ' && *s != '\t' && *s != 10 && *s != 13) \
|
|
Toshihiro Shimizu |
890ddd |
s++; \
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*------------------------------------------------------------------------*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef WIN32
|
|
Toshihiro Shimizu |
890ddd |
#include <stdlib.h></stdlib.h>
|
|
Toshihiro Shimizu |
890ddd |
#define TOONZMAXPATHLEN _MAX_PATH
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
#include <sys param.h=""></sys>
|
|
Toshihiro Shimizu |
890ddd |
#define TOONZMAXPATHLEN MAXPATHLEN
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*------------------------------------------------------------------------*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int get_frame_number(char *s)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int j, i = 0;
|
|
Toshihiro Shimizu |
890ddd |
while (s[i] && (s[i] < '0' || s[i] > '9'))
|
|
Toshihiro Shimizu |
890ddd |
i++;
|
|
Toshihiro Shimizu |
890ddd |
if (!s[i])
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
j = i;
|
|
Toshihiro Shimizu |
890ddd |
while (s[i] && (s[i] >= '0' && s[i] <= '9'))
|
|
Toshihiro Shimizu |
890ddd |
i++;
|
|
Toshihiro Shimizu |
890ddd |
s[i] = '\0';
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return (atoi(s + j));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//==============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int compute_casm_range(const char *filename, int &start, int &end, bool &interlaced)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
FILE *fp;
|
|
Toshihiro Shimizu |
890ddd |
bool first_flag = true;
|
|
Toshihiro Shimizu |
890ddd |
int cnt, frame = 1;
|
|
Toshihiro Shimizu |
890ddd |
char buffer[TOONZMAXPATHLEN], *s;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
start = 0;
|
|
Toshihiro Shimizu |
890ddd |
end = 0;
|
|
Toshihiro Shimizu |
890ddd |
interlaced = false;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (filename)
|
|
Toshihiro Shimizu |
890ddd |
fp = fopen(filename, "r");
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
fp = fdopen(0, "r");
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!fp)
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
cnt = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
while (fgets(buffer, TOONZMAXPATHLEN, fp)) {
|
|
Toshihiro Shimizu |
890ddd |
s = buffer;
|
|
Toshihiro Shimizu |
890ddd |
SKIP_BLANKS(s)
|
|
Toshihiro Shimizu |
890ddd |
if (strncmp(s, "FRAME", 5) == 0) {
|
|
Toshihiro Shimizu |
890ddd |
frame = get_frame_number(s);
|
|
Toshihiro Shimizu |
890ddd |
if (first_flag) {
|
|
Toshihiro Shimizu |
890ddd |
start = frame;
|
|
Toshihiro Shimizu |
890ddd |
first_flag = false;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
cnt++;
|
|
Toshihiro Shimizu |
890ddd |
} else if (strncmp(s, "FIELD", 5) == 0)
|
|
Toshihiro Shimizu |
890ddd |
interlaced = true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!first_flag)
|
|
Toshihiro Shimizu |
890ddd |
end = frame;
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Toshihiro Shimizu |
890ddd |
start = 0;
|
|
Toshihiro Shimizu |
890ddd |
end = 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (fp != stdin)
|
|
Toshihiro Shimizu |
890ddd |
fclose(fp);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (interlaced) {
|
|
Toshihiro Shimizu |
890ddd |
start = ((start) + 1) / 2;
|
|
Toshihiro Shimizu |
890ddd |
end = ((end) + 1) / 2;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return cnt;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//==============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
CasmFileInfo::CasmFileInfo(const TFilePath &fp)
|
|
Toshihiro Shimizu |
890ddd |
: m_fp(fp)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void CasmFileInfo::getFrameRange(int &startFrame, int &endFrame, bool &interlaced)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int rc = compute_casm_range(
|
|
Toshihiro Shimizu |
890ddd |
toString(m_fp.getWideString()).c_str(),
|
|
Toshihiro Shimizu |
890ddd |
startFrame, endFrame, interlaced);
|
|
Toshihiro Shimizu |
890ddd |
}
|