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