Shinya Kitaoka 79e39b
#include <memory></memory>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tmachine.h"
Toshihiro Shimizu 890ddd
#include "pli_io.h"
Toshihiro Shimizu 890ddd
#include "tcommon.h"
Toshihiro Shimizu 890ddd
#include "timage_io.h"
Toshihiro Shimizu 890ddd
#include "tvectorimage.h"
Toshihiro Shimizu 890ddd
//#include "tstrokeoutline.h"
Toshihiro Shimizu 890ddd
#include "tsimplecolorstyles.h"
Toshihiro Shimizu 890ddd
#include "tcontenthistory.h"
Toshihiro Shimizu 890ddd
#include "tfilepath_io.h"
Toshihiro Shimizu 890ddd
//#include <fstream.h></fstream.h>
Toshihiro Shimizu 890ddd
#include "../compatibility/tfile_io.h"
Toshihiro Shimizu 890ddd
#include "tenv.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#if defined(MACOSX)
Toshihiro Shimizu 890ddd
#include <architecture i386="" io.h=""></architecture>
Shinya Kitaoka 9f5a1b
#elif defined(_WIN32)
Toshihiro Shimizu 890ddd
#include <io.h></io.h>
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using namespace std;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
typedef TVectorImage::IntersectionBranch IntersectionBranch;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#if !defined(TNZ_LITTLE_ENDIAN)
Toshihiro Shimizu 890ddd
TNZ_LITTLE_ENDIAN undefined !!
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    static const int c_majorVersionNumber = 71;
Shinya Kitaoka 120a6e
static const int c_minorVersionNumber     = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
inline void ulongFromDouble1(double x, TUINT32 &hi, TUINT32 &lo) {
Shinya Kitaoka 120a6e
  assert(x < 1.0);
Shinya Kitaoka 120a6e
  // x+=1.0;
Shinya Kitaoka 120a6e
  TUINT32 *l = (TUINT32 *)&x;
Toshihiro Shimizu 890ddd
#if TNZ_LITTLE_ENDIAN
Shinya Kitaoka 120a6e
  hi = l[1], lo = l[0];
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
  hi = l[0], lo = l[1];
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // return (hi&0XFFFFF)<<12 | ((lo&0xFFE00000)>>20);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
inline double doubleFromUlong1(TUINT32 hi, TUINT32 lo) {
Shinya Kitaoka 120a6e
  // assert((lo&0X00000001)==0);
Shinya Kitaoka 120a6e
  TUINT32 l[2];
Toshihiro Shimizu 890ddd
#if TNZ_LITTLE_ENDIAN
Shinya Kitaoka 120a6e
  l[1] = hi;
Shinya Kitaoka 120a6e
  l[0] = lo;
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
  l[0]             = hi;
Shinya Kitaoka 120a6e
  l[1]             = lo;
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return *(double *)l;  // - 1;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Campbell Barton 8c6c57
static TThickPoint operator*(const TAffine &aff, const TThickPoint &p) {
Shinya Kitaoka 120a6e
  TPointD p1(p.x, p.y);
Shinya Kitaoka 120a6e
  return TThickPoint(aff * p1, p.thick);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class MyOfstream final : public Tofstream {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  MyOfstream(const TFilePath &path) : Tofstream(path) {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  MyOfstream &operator<<(TUINT32 n) {
Shinya Kitaoka 120a6e
    TUINT32 app;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#if TNZ_LITTLE_ENDIAN
Shinya Kitaoka 120a6e
    app = n;
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
    UCHAR *uc      = (UCHAR *)&n;
Shinya Kitaoka 120a6e
    app            = *(uc) | (*(uc + 1)) << 8 | (*(uc + 2)) << 16 | (*(uc + 3)) << 24;
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
    write((char *)&app, sizeof(TUINT32));
Shinya Kitaoka 120a6e
    return *this;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  MyOfstream &operator<<(USHORT n) {
Shinya Kitaoka 120a6e
    USHORT app;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#if TNZ_LITTLE_ENDIAN
Shinya Kitaoka 120a6e
    app = n;
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
    UCHAR *uc      = (UCHAR *)&n;
Shinya Kitaoka 120a6e
    app            = *(uc) | (*(uc + 1)) << 8;
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    write((char *)&app, sizeof(USHORT));
Shinya Kitaoka 120a6e
    return *this;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  MyOfstream &operator<<(UCHAR un) {
Shinya Kitaoka 120a6e
    write((char *)&un, sizeof(UCHAR));
Shinya Kitaoka 120a6e
    return *this;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  MyOfstream &operator<<(char un) {
Shinya Kitaoka 120a6e
    write((char *)&un, sizeof(char));
Shinya Kitaoka 120a6e
    return *this;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  MyOfstream &operator<<(const TRaster32P &r);
Shinya Kitaoka 120a6e
  MyOfstream &operator<<(const std::string &r);
Shinya Kitaoka 120a6e
  MyOfstream &writeBuf(void *un, UINT s) {
Shinya Kitaoka 120a6e
    write((char *)un, s);
Shinya Kitaoka 120a6e
    return *this;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
MyOfstream &MyOfstream::operator<<(const TRaster32P &r) {
Shinya Kitaoka 120a6e
  assert(r->getLx() == r->getWrap());
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  (*this) << (USHORT)r->getLx();
Shinya Kitaoka 120a6e
  (*this) << (USHORT)r->getLy();
Shinya Kitaoka 120a6e
  r->lock();
Shinya Kitaoka 120a6e
  MyOfstream &ret =
Shinya Kitaoka 120a6e
      writeBuf(r->getRawData(), r->getLx() * r->getLy() * r->getPixelSize());
Shinya Kitaoka 120a6e
  r->unlock();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return ret;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
MyOfstream &MyOfstream::operator<<(const std::string &s) {
Shinya Kitaoka 120a6e
  (*this) << (USHORT)s.size();
Shinya Kitaoka 120a6e
  for (UINT i = 0; i < s.size(); i++) (*this) << (UCHAR)(s[i]);
Shinya Kitaoka 120a6e
  return *this;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class MyIfstream  // The input is done without stl; it was crashing in release
Shinya Kitaoka 120a6e
                  // version loading textures!!
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  bool m_isIrixEndian;
Shinya Kitaoka 120a6e
  FILE *m_fp;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  MyIfstream() : m_isIrixEndian(false) { m_fp = 0; }
Shinya Kitaoka 120a6e
  ~MyIfstream() {
Shinya Kitaoka 120a6e
    if (m_fp) fclose(m_fp);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  void setEndianess(bool isIrixEndian) { m_isIrixEndian = isIrixEndian; }
Shinya Kitaoka 120a6e
  MyIfstream &operator>>(TUINT32 &un);
Shinya Kitaoka 120a6e
  MyIfstream &operator>>(string &un);
Shinya Kitaoka 120a6e
  MyIfstream &operator>>(USHORT &un);
Shinya Kitaoka 120a6e
  MyIfstream &operator>>(UCHAR &un);
Shinya Kitaoka 120a6e
  MyIfstream &operator>>(char &un);
Shinya Kitaoka 120a6e
  void open(const TFilePath &filename);
Shinya Kitaoka 120a6e
  void close() {
Shinya Kitaoka 120a6e
    if (m_fp) fclose(m_fp);
Shinya Kitaoka 120a6e
    m_fp = 0;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  TUINT32 tellg() { return (TUINT32)ftell(m_fp); }
Shinya Kitaoka 120a6e
  // void seekg(TUINT32 pos, ios_base::seek_dir type);
Shinya Kitaoka 120a6e
  void seekg(TUINT32 pos, int type);
Shinya Kitaoka 120a6e
  void read(char *m_buf, int length) {
Shinya Kitaoka 120a6e
    fread((void *)m_buf, sizeof(char), length, m_fp);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void MyIfstream::open(const TFilePath &filename) {
Shinya Kitaoka 120a6e
  try {
Shinya Kitaoka 120a6e
    m_fp = fopen(filename, "rb");
Shinya Kitaoka 120a6e
  } catch (TException &) {
Shinya Kitaoka 120a6e
    throw TImageException(filename, "File not found");
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void MyIfstream::seekg(TUINT32 pos, int type) {
Shinya Kitaoka 120a6e
  if (type == ios_base::beg)
Shinya Kitaoka 120a6e
    fseek(m_fp, pos, SEEK_SET);
Shinya Kitaoka 120a6e
  else if (type == ios_base::cur)
Shinya Kitaoka 120a6e
    fseek(m_fp, pos, SEEK_CUR);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    assert(false);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
inline MyIfstream &MyIfstream::operator>>(UCHAR &un) {
Shinya Kitaoka 120a6e
  int ret = fread((void *)&un, sizeof(UCHAR), 1, m_fp);
Shinya Kitaoka 120a6e
  if (ret < 1) throw TException("corrupted pli file: unexpected end of file");
Shinya Kitaoka 120a6e
  // read((char *)&un, sizeof(UCHAR));
Shinya Kitaoka 120a6e
  return *this;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
inline MyIfstream &MyIfstream::operator>>(char &un) {
Shinya Kitaoka 120a6e
  int ret = fread((void *)&un, sizeof(char), 1, m_fp);
Shinya Kitaoka 120a6e
  if (ret < 1) throw TException("corrupted pli file: unexpected end of file");
Shinya Kitaoka 120a6e
  // read((char *)&un, sizeof(char));
Shinya Kitaoka 120a6e
  return *this;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
inline MyIfstream &MyIfstream::operator>>(USHORT &un) {
Shinya Kitaoka 120a6e
  int ret = fread((void *)&un, sizeof(USHORT), 1, m_fp);
Shinya Kitaoka 120a6e
  if (ret < 1) throw TException("corrupted pli file: unexpected end of file");
Shinya Kitaoka 120a6e
  //  read((char *)&un, sizeof(USHORT));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (m_isIrixEndian) un = ((un & 0xff00) >> 8) | ((un & 0x00ff) << 8);
Shinya Kitaoka 120a6e
  return *this;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
inline MyIfstream &MyIfstream::operator>>(TUINT32 &un) {
Shinya Kitaoka 120a6e
  int ret = fread((void *)&un, sizeof(TUINT32), 1, m_fp);
Shinya Kitaoka 120a6e
  if (ret < 1) throw TException("corrupted pli file: unexpected end of file");
Shinya Kitaoka 120a6e
  // read((char *)&un, sizeof(TUINT32));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (m_isIrixEndian)
Shinya Kitaoka 120a6e
    un = ((un & 0xff000000) >> 24) | ((un & 0x00ff0000) >> 8) |
Shinya Kitaoka 120a6e
         ((un & 0x0000ff00) << 8) | ((un & 0x000000ff) << 24);
Shinya Kitaoka 120a6e
  return *this;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
inline MyIfstream &MyIfstream::operator>>(string &un) {
Shinya Kitaoka 120a6e
  string s = "";
MCCCS a0ce32
  USHORT length;
MCCCS a0ce32
  (*this) >> length;
MCCCS a0ce32
  for (UINT i = 0; i < length; i++) {
Shinya Kitaoka 120a6e
    UCHAR ch;
Shinya Kitaoka 120a6e
    (*this) >> ch;
Shinya Kitaoka 120a6e
    s.append(1, ch);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  un = s;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return *this;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
UINT TStyleParam::getSize() {
Shinya Kitaoka 120a6e
  switch (m_type) {
Shinya Kitaoka 120a6e
  case SP_BYTE:
Shinya Kitaoka 120a6e
    return 1;
Shinya Kitaoka 120a6e
  case SP_INT:
Shinya Kitaoka 120a6e
    return 4;
Shinya Kitaoka 120a6e
  case SP_DOUBLE:
Shinya Kitaoka 120a6e
    return 4;
Shinya Kitaoka 120a6e
  case SP_USHORT:
Shinya Kitaoka 120a6e
    return 2;
Shinya Kitaoka 120a6e
  case SP_RASTER:
Shinya Kitaoka 120a6e
    return 2 + 2 + m_r->getLx() * m_r->getLy() * m_r->getPixelSize();
Shinya Kitaoka 120a6e
  case SP_STRING:
Shinya Kitaoka 120a6e
    return (m_string.size() + sizeof(USHORT));
Shinya Kitaoka 120a6e
  default:
Shinya Kitaoka 120a6e
    assert(false);
Shinya Kitaoka 120a6e
    return 0;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#define CHECK_FOR_READ_ERROR(filePath)
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
#define CHECK_FOR_WRITE_ERROR(filePath)                                        \
Shinya Kitaoka 120a6e
  {                                                                            \
Shinya Kitaoka 120a6e
    if (m_oChan->fail() /*m_oChan.flags()&(ios::failbit)*/) {                  \
Shinya Kitaoka 120a6e
      m_lastError = WRITE_ERROR;                                               \
Shinya Kitaoka 120a6e
      throw TImageException(filePath, "Error on writing file");                \
Shinya Kitaoka 120a6e
    }                                                                          \
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
const TUINT32 c_magicNt   = 0x4D494C50;
Toshihiro Shimizu 890ddd
const TUINT32 c_magicIrix = 0x504C494D;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class TagElem {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  PliTag *m_tag;
Shinya Kitaoka 120a6e
  TUINT32 m_offset;
Shinya Kitaoka 120a6e
  TagElem *m_next;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TagElem(PliTag *tag, TUINT32 offset, TagElem *next = NULL)
Shinya Kitaoka 120a6e
      : m_tag(tag), m_offset(offset), m_next(next) {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TagElem(const TagElem &elem)
Shinya Kitaoka 120a6e
      : m_tag(elem.m_tag), m_offset(elem.m_offset), m_next(NULL) {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  ~TagElem() {
Shinya Kitaoka 120a6e
    if (m_tag) delete m_tag;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
class TContentHistory;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class ParsedPliImp {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  UCHAR m_majorVersionNumber;
Shinya Kitaoka 120a6e
  UCHAR m_minorVersionNumber;
Shinya Kitaoka 120a6e
  USHORT m_framesNumber;
Shinya Kitaoka 120a6e
  double m_thickRatio;
Shinya Kitaoka 120a6e
  double m_maxThickness;
Shinya Kitaoka 120a6e
  double m_autocloseTolerance;
Shinya Kitaoka 120a6e
  bool m_isIrixEndian;
Shinya Kitaoka 120a6e
  TFilePath m_filePath;
Shinya Kitaoka 120a6e
  UCHAR m_currDinamicTypeBytesNum;
Shinya Kitaoka 120a6e
  TUINT32 m_tagLength;
Shinya Kitaoka 120a6e
  TUINT32 m_bufLength;
Shinya Kitaoka 120a6e
  std::unique_ptr<uchar[]> m_buf;</uchar[]>
Shinya Kitaoka 120a6e
  TAffine m_affine;
Shinya Kitaoka 120a6e
  int m_precisionScale;
Shinya Kitaoka 120a6e
  std::map<tframeid, int=""> m_frameOffsInFile;</tframeid,>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  PliTag *readTextTag();
Shinya Kitaoka 120a6e
  PliTag *readPaletteTag();
Shinya Kitaoka 120a6e
  PliTag *readPaletteWithAlphaTag();
Shinya Kitaoka 120a6e
  PliTag *readThickQuadraticChainTag(bool isLoop);
Shinya Kitaoka 120a6e
  PliTag *readColorTag();
Shinya Kitaoka 120a6e
  PliTag *readStyleTag();
Shinya Kitaoka 120a6e
  PliTag *readGroupTag();
Shinya Kitaoka 120a6e
  PliTag *readImageTag();
Shinya Kitaoka 120a6e
  PliTag *readGeometricTransformationTag();
Shinya Kitaoka 120a6e
  PliTag *readDoublePairTag();
Shinya Kitaoka 120a6e
  PliTag *readBitmapTag();
Shinya Kitaoka 120a6e
  PliTag *readIntersectionDataTag();
Shinya Kitaoka 120a6e
  PliTag *readOutlineOptionsTag();
Shinya Kitaoka 120a6e
  PliTag *readPrecisionScaleTag();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  inline void readDinamicData(TUINT32 &val, TUINT32 &bufOffs);
Shinya Kitaoka 120a6e
  inline bool readDinamicData(TINT32 &val, TUINT32 &bufOffs);
Shinya Kitaoka 120a6e
  inline void readFloatData(double &val, TUINT32 &bufOffs);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  inline UINT readRasterData(TRaster32P &r, TUINT32 &bufOffs);
Shinya Kitaoka 120a6e
  inline void writeFloatData(double val);
Shinya Kitaoka 120a6e
  inline void readUShortData(USHORT &val, TUINT32 &bufOffs);
Shinya Kitaoka 120a6e
  inline void readTUINT32Data(TUINT32 &val, TUINT32 &bufOffs);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TUINT32 writeTagHeader(UCHAR type, UINT tagLength);
Shinya Kitaoka 120a6e
  TUINT32 writeTextTag(TextTag *tag);
Shinya Kitaoka 120a6e
  TUINT32 writePaletteTag(PaletteTag *tag);
Shinya Kitaoka 120a6e
  TUINT32 writePaletteWithAlphaTag(PaletteWithAlphaTag *tag);
Shinya Kitaoka 120a6e
  TUINT32 writeThickQuadraticChainTag(ThickQuadraticChainTag *tag);
Shinya Kitaoka 120a6e
  TUINT32 writeGroupTag(GroupTag *tag);
Shinya Kitaoka 120a6e
  TUINT32 writeImageTag(ImageTag *tag);
Shinya Kitaoka 120a6e
  TUINT32 writeColorTag(ColorTag *tag);
Shinya Kitaoka 120a6e
  TUINT32 writeStyleTag(StyleTag *tag);
Shinya Kitaoka 120a6e
  TUINT32 writeGeometricTransformationTag(GeometricTransformationTag *tag);
Shinya Kitaoka 120a6e
  TUINT32 writeDoublePairTag(DoublePairTag *tag);
Shinya Kitaoka 120a6e
  TUINT32 writeBitmapTag(BitmapTag *tag);
Shinya Kitaoka 120a6e
  TUINT32 writeIntersectionDataTag(IntersectionDataTag *tag);
Shinya Kitaoka 120a6e
  TUINT32 writeOutlineOptionsTag(StrokeOutlineOptionsTag *tag);
Shinya Kitaoka 120a6e
  TUINT32 writePrecisionScaleTag(PrecisionScaleTag *tag);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  inline void writeDinamicData(TUINT32 val);
Shinya Kitaoka 120a6e
  inline void writeDinamicData(TINT32 val, bool isNegative);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  inline void setDinamicTypeBytesNum(int minval, int maxval);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  PliTag *findTagFromOffset(UINT tagOffs);
Shinya Kitaoka 120a6e
  UINT findOffsetFromTag(PliTag *tag);
Shinya Kitaoka 120a6e
  TagElem *findTag(PliTag *tag);
Shinya Kitaoka 120a6e
  USHORT readTagHeader();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  enum errorType {
Shinya Kitaoka 120a6e
    NO__ERROR = 0,
Shinya Kitaoka 120a6e
    NO_FILE,
Shinya Kitaoka 120a6e
    BAD_MAGIC,
Shinya Kitaoka 120a6e
    PREMATURE_EOF,
Shinya Kitaoka 120a6e
    WRITE_ERROR,
Shinya Kitaoka 120a6e
    ERRORTYPE_HOW_MANY
Shinya Kitaoka 120a6e
  };
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  errorType m_lastError;
Shinya Kitaoka 120a6e
  string m_creator;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TagElem *m_firstTag;
Shinya Kitaoka 120a6e
  TagElem *m_lastTag;
Shinya Kitaoka 120a6e
  TagElem *m_currTag;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  MyIfstream m_iChan;
Shinya Kitaoka 120a6e
  MyOfstream *m_oChan;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  ParsedPliImp();
Shinya Kitaoka 120a6e
  ParsedPliImp(UCHAR majorVersionNumber, UCHAR minorVersionNumber,
Shinya Kitaoka 120a6e
               USHORT framesNumber, UCHAR precision, UCHAR maxThickness,
Shinya Kitaoka 120a6e
               double autocloseTolerance);
Shinya Kitaoka 120a6e
  ParsedPliImp(const TFilePath &filename, bool readInfo);
Shinya Kitaoka 120a6e
  ~ParsedPliImp();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void setFrameCount(int frameCount);
Shinya Kitaoka 120a6e
  int getFrameCount();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void loadInfo(bool readPalette, TPalette *&palette,
Shinya Kitaoka 120a6e
                TContentHistory *&history);
Shinya Kitaoka 120a6e
  ImageTag *loadFrame(const TFrameId &frameNumber);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TagElem *readTag();
Shinya Kitaoka 120a6e
  void writeTag(TagElem *tag);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool addTag(PliTag *tag, bool addFront = false);
Shinya Kitaoka 120a6e
  bool addTag(const TagElem &tag, bool addFront = false);
Shinya Kitaoka 120a6e
  bool writePli(const TFilePath &filename);
Shinya Kitaoka 120a6e
  inline void WRITE_UCHAR_FROM_DOUBLE(double dval);
Shinya Kitaoka 120a6e
  inline void WRITE_SHORT_FROM_DOUBLE(double dval);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
double ParsedPli::getMaxThickness() const { return imp->m_maxThickness; };
Shinya Kitaoka 120a6e
void ParsedPli::setMaxThickness(double maxThickness) {
Shinya Kitaoka 120a6e
  imp->m_maxThickness = maxThickness;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Campbell Barton b130ec
/* indirect inclusion of <math.h> causes 'abs' to return double on Linux */</math.h>
Campbell Barton b130ec
#ifdef LINUX
Campbell Barton b130ec
template <typename t=""></typename>
Campbell Barton b130ec
T abs_workaround(T a) {
Campbell Barton b130ec
  return (a > 0) ? a : -a;
Campbell Barton b130ec
}
Campbell Barton b130ec
#define abs abs_workaround
Campbell Barton b130ec
#endif
Campbell Barton b130ec
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
static inline UCHAR complement1(char val, bool isNegative = false) {
Shinya Kitaoka 120a6e
  if (val == 0) return isNegative ? 0x80 : 0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return (UCHAR)(abs(val) | (val & 0x80));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
static inline USHORT complement1(short val, bool isNegative = false) {
Shinya Kitaoka 120a6e
  if (val == 0) return isNegative ? 0x8000 : 0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return (USHORT)(abs(val) | (val & 0x8000));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
static inline TUINT32 complement1(TINT32 val, bool isNegative = false) {
Shinya Kitaoka 120a6e
  if (val == 0) return isNegative ? 0x80000000 : 0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return (TUINT32)(abs(val) | (val & 0x80000000));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
static inline short complement2(USHORT val) {
Shinya Kitaoka 120a6e
  return (val & 0x8000) ? -(val & 0x7fff) : (val & 0x7fff);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Campbell Barton b130ec
#ifdef LINUX
Campbell Barton b130ec
#undef abs
Campbell Barton b130ec
#endif
Campbell Barton b130ec
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
ParsedPliImp::ParsedPliImp()
Shinya Kitaoka 120a6e
    : m_majorVersionNumber(0)
Shinya Kitaoka 120a6e
    , m_minorVersionNumber(0)
Shinya Kitaoka 120a6e
    , m_framesNumber(0)
Shinya Kitaoka 120a6e
    , m_thickRatio(1.0)
Shinya Kitaoka 120a6e
    , m_maxThickness(0.0)
Shinya Kitaoka 120a6e
    , m_firstTag(NULL)
Shinya Kitaoka 120a6e
    , m_lastTag(NULL)
Shinya Kitaoka 120a6e
    , m_currTag(NULL)
Shinya Kitaoka 120a6e
    , m_iChan()
Shinya Kitaoka 120a6e
    , m_oChan(0)
Shinya Kitaoka 120a6e
    , m_bufLength(0)
Shinya Kitaoka 120a6e
    , m_affine()
Shinya Kitaoka 120a6e
    , m_precisionScale(REGION_COMPUTING_PRECISION)
Shinya Kitaoka 120a6e
    , m_creator("") {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
/*=====================================================================*/
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
ParsedPliImp::ParsedPliImp(UCHAR majorVersionNumber, UCHAR minorVersionNumber,
Shinya Kitaoka 120a6e
                           USHORT framesNumber, UCHAR precision,
Shinya Kitaoka 120a6e
                           UCHAR maxThickness, double autocloseTolerance)
Shinya Kitaoka 120a6e
    : m_majorVersionNumber(majorVersionNumber)
Shinya Kitaoka 120a6e
    , m_minorVersionNumber(minorVersionNumber)
Shinya Kitaoka 120a6e
    , m_framesNumber(framesNumber)
Shinya Kitaoka 120a6e
    , m_maxThickness(maxThickness)
Shinya Kitaoka 120a6e
    , m_autocloseTolerance(autocloseTolerance)
Shinya Kitaoka 120a6e
    , m_thickRatio(maxThickness / 255.0)
Shinya Kitaoka 120a6e
    , m_firstTag(NULL)
Shinya Kitaoka 120a6e
    , m_lastTag(NULL)
Shinya Kitaoka 120a6e
    , m_currTag(NULL)
Shinya Kitaoka 120a6e
    , m_iChan()
Shinya Kitaoka 120a6e
    , m_oChan(0)
Shinya Kitaoka 120a6e
    , m_bufLength(0)
Shinya Kitaoka 120a6e
    , m_affine(TScale(1.0 / pow(10.0, precision)))
Shinya Kitaoka 120a6e
    , m_precisionScale(REGION_COMPUTING_PRECISION)
Shinya Kitaoka 120a6e
    , m_creator("") {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
ParsedPliImp::ParsedPliImp(const TFilePath &filename, bool readInfo)
Shinya Kitaoka 120a6e
    : m_majorVersionNumber(0)
Shinya Kitaoka 120a6e
    , m_minorVersionNumber(0)
Shinya Kitaoka 120a6e
    , m_framesNumber(0)
Shinya Kitaoka 120a6e
    , m_thickRatio(1.0)
Shinya Kitaoka 120a6e
    , m_maxThickness(0)
Shinya Kitaoka 120a6e
    , m_firstTag(NULL)
Shinya Kitaoka 120a6e
    , m_lastTag(NULL)
Shinya Kitaoka 120a6e
    , m_currTag(NULL)
Shinya Kitaoka 120a6e
    , m_iChan()
Shinya Kitaoka 120a6e
    , m_oChan(0)
Shinya Kitaoka 120a6e
    , m_bufLength(0)
Shinya Kitaoka 120a6e
    , m_precisionScale(REGION_COMPUTING_PRECISION)
Shinya Kitaoka 120a6e
    , m_creator("") {
Shinya Kitaoka 120a6e
  TUINT32 magic;
MCCCS a0ce32
  //  TUINT32 fileLength;
Shinya Kitaoka 120a6e
  TagElem *tagElem;
Shinya Kitaoka 120a6e
  UCHAR maxThickness;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // cerr<
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //#ifdef _WIN32
Shinya Kitaoka 120a6e
  m_iChan.open(filename);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // m_iChan.exceptions( ios::failbit | ios::badbit);
Shinya Kitaoka 120a6e
  //#else
Shinya Kitaoka 120a6e
  //  m_iChan.open(filename.c_str(), ios::in);
Shinya Kitaoka 120a6e
  //#endif
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_iChan >> magic;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  CHECK_FOR_READ_ERROR(filename);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (magic == c_magicNt) {
Toshihiro Shimizu 890ddd
#if TNZ_LITTLE_ENDIAN
Shinya Kitaoka 120a6e
    m_isIrixEndian = false;
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
    m_isIrixEndian = true;
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
    m_iChan.setEndianess(false);
Shinya Kitaoka 120a6e
  } else if (magic == c_magicIrix) {
Toshihiro Shimizu 890ddd
#if TNZ_LITTLE_ENDIAN
Shinya Kitaoka 120a6e
    m_isIrixEndian = true;
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
    m_isIrixEndian = false;
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
    m_iChan.setEndianess(true);
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    m_lastError = BAD_MAGIC;
Shinya Kitaoka 120a6e
    throw TImageException(filename, "Error on reading magic number");
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_iChan >> m_majorVersionNumber;
Shinya Kitaoka 120a6e
  m_iChan >> m_minorVersionNumber;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Loading pli versions AFTER current one is NOT SUPPORTED. This means that an
Shinya Kitaoka 120a6e
  // exception is directly called at this point.
Shinya Kitaoka 120a6e
  if (m_majorVersionNumber > c_majorVersionNumber ||
Shinya Kitaoka 120a6e
      (m_majorVersionNumber == c_majorVersionNumber &&
Shinya Kitaoka 120a6e
       m_minorVersionNumber > c_minorVersionNumber))
Shinya Kitaoka 120a6e
    throw TImageVersionException(filename, m_majorVersionNumber,
Shinya Kitaoka 120a6e
                                 m_minorVersionNumber);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (m_majorVersionNumber > 5 ||
Shinya Kitaoka 120a6e
      m_majorVersionNumber == 5 && m_minorVersionNumber >= 8)
Shinya Kitaoka 120a6e
    m_iChan >> m_creator;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (m_majorVersionNumber < 5) {
MCCCS a0ce32
    TUINT32 fileLength;
Toshihiro Shimizu 890ddd
MCCCS a0ce32
    m_iChan >> fileLength;
Shinya Kitaoka 120a6e
    m_iChan >> m_framesNumber;
Shinya Kitaoka 120a6e
    m_iChan >> maxThickness;
Shinya Kitaoka 120a6e
    m_thickRatio = maxThickness / 255.0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    if (readInfo) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    CHECK_FOR_READ_ERROR(filename);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    m_currDinamicTypeBytesNum = 2;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    while ((tagElem = readTag())) {
Shinya Kitaoka 120a6e
      if (!m_firstTag)
Shinya Kitaoka 120a6e
        m_firstTag = m_lastTag = tagElem;
Shinya Kitaoka 120a6e
      else {
Shinya Kitaoka 120a6e
        m_lastTag->m_next = tagElem;
Shinya Kitaoka 120a6e
        m_lastTag         = m_lastTag->m_next;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    for (tagElem = m_firstTag; tagElem; tagElem = tagElem->m_next)
Shinya Kitaoka 120a6e
      tagElem->m_offset = 0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    m_iChan.close();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
extern TPalette *readPalette(GroupTag *paletteTag, int majorVersion,
Shinya Kitaoka 120a6e
                             int minorVersion);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
const TFrameId &ParsedPli::getFrameNumber(int index) {
Shinya Kitaoka 120a6e
  assert(imp->m_frameOffsInFile.size() == imp->m_framesNumber);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  std::map<tframeid, int="">::iterator it = imp->m_frameOffsInFile.begin();</tframeid,>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  std::advance(it, index);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return it->first;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ParsedPliImp::loadInfo(bool readPlt, TPalette *&palette,
Shinya Kitaoka 120a6e
                            TContentHistory *&history) {
MCCCS a0ce32
  TUINT32 fileLength;
Shinya Kitaoka 120a6e
MCCCS a0ce32
  m_iChan >> fileLength;
Shinya Kitaoka 120a6e
  m_iChan >> m_framesNumber;
Shinya Kitaoka 120a6e
  if (!((m_majorVersionNumber == 5 && m_minorVersionNumber >= 7) ||
Shinya Kitaoka 120a6e
        (m_majorVersionNumber > 5))) {
Shinya Kitaoka 120a6e
    UCHAR maxThickness;
Shinya Kitaoka 120a6e
    m_iChan >> maxThickness;
Shinya Kitaoka 120a6e
    m_thickRatio = maxThickness / 255.0;
Shinya Kitaoka 120a6e
  } else
Shinya Kitaoka 120a6e
    m_thickRatio = 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  UCHAR ii, d, s = 2;
Shinya Kitaoka 120a6e
  if (m_majorVersionNumber > 6 ||
Shinya Kitaoka 120a6e
      (m_majorVersionNumber == 6 && m_minorVersionNumber >= 5))
Shinya Kitaoka 120a6e
    m_iChan >> s;
Shinya Kitaoka 120a6e
  m_iChan >> ii;
Shinya Kitaoka 120a6e
  m_iChan >> d;
Shinya Kitaoka 120a6e
  m_autocloseTolerance = ((double)(s - 1)) * (ii + 0.01 * d);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_currDinamicTypeBytesNum = 2;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // m_frameOffsInFile = new int[m_framesNumber];
Shinya Kitaoka 120a6e
  // for (int i=0; i
Shinya Kitaoka 120a6e
  //  m_frameOffsInFile[i] = -1;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TUINT32 pos = m_iChan.tellg();
Shinya Kitaoka 120a6e
  USHORT type;
Shinya Kitaoka 120a6e
  while ((type = readTagHeader()) != PliTag::END_CNTRL) {
Shinya Kitaoka 120a6e
    if (type == PliTag::IMAGE_BEGIN_GOBJ) {
Shinya Kitaoka 120a6e
      USHORT frame;
Shinya Kitaoka 120a6e
      m_iChan >> frame;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      char letter = 0;
Shinya Kitaoka 120a6e
      if (m_majorVersionNumber > 6 ||
Shinya Kitaoka 120a6e
          (m_majorVersionNumber == 6 && m_minorVersionNumber >= 6))
Shinya Kitaoka 120a6e
        m_iChan >> letter;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      m_frameOffsInFile[TFrameId(frame, letter)] = m_iChan.tellg();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      // m_iChan.seekg(m_tagLength, ios::cur);
Shinya Kitaoka 120a6e
      m_iChan.seekg(m_tagLength - 2, ios::cur);
Shinya Kitaoka 120a6e
    } else if (type == PliTag::STYLE_NGOBJ) {
Shinya Kitaoka 120a6e
      m_iChan.seekg(pos, ios::beg);
Shinya Kitaoka 120a6e
      TagElem *tagElem = readTag();
Shinya Kitaoka 120a6e
      addTag(*tagElem);
Shinya Kitaoka 120a6e
      tagElem->m_tag = 0;
Shinya Kitaoka 120a6e
      delete tagElem;
Shinya Kitaoka 120a6e
    } else if (type == PliTag::TEXT) {
Shinya Kitaoka 120a6e
      m_iChan.seekg(pos, ios::beg);
Shinya Kitaoka 120a6e
      TagElem *tagElem = readTag();
Shinya Kitaoka 120a6e
      TextTag *textTag = (TextTag *)tagElem->m_tag;
Shinya Kitaoka 120a6e
      history          = new TContentHistory(true);
Shinya Kitaoka 120a6e
      history->deserialize(QString::fromStdString(textTag->m_text));
Shinya Kitaoka 120a6e
      delete tagElem;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    else if (type == PliTag::GROUP_GOBJ && readPlt)  // la paletta!!!
Shinya Kitaoka 120a6e
    {
Shinya Kitaoka 120a6e
      m_iChan.seekg(pos, ios::beg);
Shinya Kitaoka 120a6e
      TagElem *tagElem   = readTag();
Shinya Kitaoka 120a6e
      GroupTag *grouptag = (GroupTag *)tagElem->m_tag;
Shinya Kitaoka 120a6e
      if (grouptag->m_type == (UCHAR)GroupTag::PALETTE) {
Shinya Kitaoka 120a6e
        readPlt = false;
Shinya Kitaoka 120a6e
        palette = readPalette((GroupTag *)tagElem->m_tag, m_majorVersionNumber,
Shinya Kitaoka 120a6e
                              m_minorVersionNumber);
Shinya Kitaoka 120a6e
      } else
Shinya Kitaoka 120a6e
        assert(grouptag->m_type == (UCHAR)GroupTag::STROKE);
Shinya Kitaoka 120a6e
      delete tagElem;
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      m_iChan.seekg(m_tagLength, ios::cur);
Shinya Kitaoka 120a6e
      switch (type) {
Shinya Kitaoka 120a6e
      case PliTag::SET_DATA_8_CNTRL:
Shinya Kitaoka 120a6e
        m_currDinamicTypeBytesNum = 1;
Shinya Kitaoka 120a6e
        break;
Shinya Kitaoka 120a6e
      case PliTag::SET_DATA_16_CNTRL:
Shinya Kitaoka 120a6e
        m_currDinamicTypeBytesNum = 2;
Shinya Kitaoka 120a6e
        break;
Shinya Kitaoka 120a6e
      case PliTag::SET_DATA_32_CNTRL:
Shinya Kitaoka 120a6e
        m_currDinamicTypeBytesNum = 4;
Shinya Kitaoka 120a6e
        break;
Shinya Kitaoka 120a6e
      default:
Shinya Kitaoka 120a6e
        break;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    pos = m_iChan.tellg();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  assert(m_frameOffsInFile.size() == m_framesNumber);
Shinya Kitaoka 120a6e
  // palette = new TPalette();
Shinya Kitaoka 120a6e
  // for (int i=0; i<256; i++)
Shinya Kitaoka 120a6e
  //  palette->getPage(0)->addStyle(TPixel::Black);
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
/*=====================================================================*/
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
USHORT ParsedPliImp::readTagHeader() {
Shinya Kitaoka 120a6e
  UCHAR ucharTagType, tagLengthId;
Shinya Kitaoka 120a6e
  USHORT tagType;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// unused variable
Toshihiro Shimizu 890ddd
#if 0
Toshihiro Shimizu 890ddd
  TUINT32 tagOffset = m_iChan.tellg();
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_iChan >> ucharTagType;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (ucharTagType == 0xFF) {
Shinya Kitaoka 120a6e
    m_iChan >> tagType;
Shinya Kitaoka 120a6e
    tagLengthId = tagType >> 14;
Shinya Kitaoka 120a6e
    tagType &= 0x3FFF;
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    tagType     = ucharTagType;
Shinya Kitaoka 120a6e
    tagLengthId = tagType >> 6;
Shinya Kitaoka 120a6e
    tagType &= 0x3F;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_tagLength = 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  switch (tagLengthId) {
Shinya Kitaoka 120a6e
  case 0x0:
Shinya Kitaoka 120a6e
    m_tagLength = 0;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 0x1: {
Shinya Kitaoka 120a6e
    UCHAR clength;
Shinya Kitaoka 120a6e
    m_iChan >> clength;
Shinya Kitaoka 120a6e
    m_tagLength = clength;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  case 0x2: {
Shinya Kitaoka 120a6e
    USHORT slength;
Shinya Kitaoka 120a6e
    m_iChan >> slength;
Shinya Kitaoka 120a6e
    m_tagLength = slength;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  case 0x3:
Shinya Kitaoka 120a6e
    m_iChan >> m_tagLength;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  default:
Shinya Kitaoka 120a6e
    assert(false);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return tagType;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
/*=====================================================================*/
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
ImageTag *ParsedPliImp::loadFrame(const TFrameId &frameNumber) {
Shinya Kitaoka 120a6e
  m_currDinamicTypeBytesNum = 2;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TagElem *tagElem = m_firstTag;
Shinya Kitaoka 120a6e
  while (tagElem) {
Shinya Kitaoka 120a6e
    TagElem *auxTag = tagElem;
Shinya Kitaoka 120a6e
    tagElem         = tagElem->m_next;
Shinya Kitaoka 120a6e
    delete auxTag;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  m_firstTag = 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // PliTag *tag;
Shinya Kitaoka 120a6e
  USHORT type = PliTag::IMAGE_BEGIN_GOBJ;
Shinya Kitaoka 120a6e
  USHORT frame;
Shinya Kitaoka 120a6e
  char letter;
Shinya Kitaoka 120a6e
  TFrameId frameId;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // cerco il frame
Shinya Kitaoka 120a6e
  std::map<tframeid, int="">::iterator it;</tframeid,>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  it = m_frameOffsInFile.find(frameNumber);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (it != m_frameOffsInFile.end()) {
Shinya Kitaoka 120a6e
    m_iChan.seekg(it->second, ios::beg);
Shinya Kitaoka 120a6e
    frameId = it->first;
Shinya Kitaoka 120a6e
  } else
Shinya Kitaoka 120a6e
    while ((type = readTagHeader()) != PliTag::END_CNTRL) {
Shinya Kitaoka 120a6e
      if (type == PliTag::IMAGE_BEGIN_GOBJ) {
Shinya Kitaoka 120a6e
        m_iChan >> frame;
Shinya Kitaoka 120a6e
        if (m_majorVersionNumber > 6 ||
Shinya Kitaoka 120a6e
            (m_majorVersionNumber == 6 && m_minorVersionNumber >= 6))
Shinya Kitaoka 120a6e
          m_iChan >> letter;
Shinya Kitaoka 120a6e
        else
Shinya Kitaoka 120a6e
          letter = 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        frameId                    = TFrameId(frame, letter);
Shinya Kitaoka 120a6e
        m_frameOffsInFile[frameId] = m_iChan.tellg();
Shinya Kitaoka 120a6e
        if (frameId == frameNumber) break;
Shinya Kitaoka 120a6e
      } else
Shinya Kitaoka 120a6e
        m_iChan.seekg(m_tagLength, ios::cur);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (type == PliTag::END_CNTRL) {
Shinya Kitaoka 120a6e
    throw TImageException(TFilePath(), "Pli: frame not found");
Shinya Kitaoka 120a6e
    return 0;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // trovato; leggo i suoi tag
Shinya Kitaoka 120a6e
  while ((tagElem = readTag())) {
Shinya Kitaoka 120a6e
    if (!m_firstTag)
Shinya Kitaoka 120a6e
      m_firstTag = m_lastTag = tagElem;
Shinya Kitaoka 120a6e
    else {
Shinya Kitaoka 120a6e
      m_lastTag->m_next = tagElem;
Shinya Kitaoka 120a6e
      m_lastTag         = m_lastTag->m_next;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    if (tagElem->m_tag->m_type == PliTag::IMAGE_GOBJ) {
Shinya Kitaoka 120a6e
      assert(((ImageTag *)(tagElem->m_tag))->m_numFrame == frameId);
Shinya Kitaoka 120a6e
      return (ImageTag *)tagElem->m_tag;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return 0;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
/*=====================================================================*/
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
TagElem *ParsedPliImp::readTag() {
Shinya Kitaoka 120a6e
  UCHAR ucharTagType, tagLengthId;
Shinya Kitaoka 120a6e
  USHORT tagType;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TUINT32 tagOffset = m_iChan.tellg();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_iChan >> ucharTagType;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (ucharTagType == 0xFF) {
Shinya Kitaoka 120a6e
    m_iChan >> tagType;
Shinya Kitaoka 120a6e
    tagLengthId = tagType >> 14;
Shinya Kitaoka 120a6e
    tagType &= 0x3FFF;
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    tagType     = ucharTagType;
Shinya Kitaoka 120a6e
    tagLengthId = tagType >> 6;
Shinya Kitaoka 120a6e
    tagType &= 0x3F;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_tagLength = 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  switch (tagLengthId) {
Shinya Kitaoka 120a6e
  case 0x0:
Shinya Kitaoka 120a6e
    m_tagLength = 0;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 0x1: {
Shinya Kitaoka 120a6e
    UCHAR clength;
Shinya Kitaoka 120a6e
    m_iChan >> clength;
Shinya Kitaoka 120a6e
    m_tagLength = clength;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  case 0x2: {
Shinya Kitaoka 120a6e
    USHORT slength;
Shinya Kitaoka 120a6e
    m_iChan >> slength;
Shinya Kitaoka 120a6e
    m_tagLength = slength;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  case 0x3:
Shinya Kitaoka 120a6e
    m_iChan >> m_tagLength;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  default:
Shinya Kitaoka 120a6e
    assert(false);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_bufLength < m_tagLength) {
Shinya Kitaoka 120a6e
    m_bufLength = m_tagLength;
Shinya Kitaoka 120a6e
    m_buf.reset(new UCHAR[m_bufLength]);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_tagLength) {
Shinya Kitaoka 120a6e
    m_iChan.read((char *)m_buf.get(), (int)m_tagLength);
Shinya Kitaoka 120a6e
    CHECK_FOR_READ_ERROR(m_filePath);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  PliTag *newTag = NULL;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  switch (tagType) {
Shinya Kitaoka 120a6e
  case PliTag::SET_DATA_8_CNTRL:
Shinya Kitaoka 120a6e
    m_currDinamicTypeBytesNum = 1;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case PliTag::SET_DATA_16_CNTRL:
Shinya Kitaoka 120a6e
    m_currDinamicTypeBytesNum = 2;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case PliTag::SET_DATA_32_CNTRL:
Shinya Kitaoka 120a6e
    m_currDinamicTypeBytesNum = 4;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case PliTag::TEXT:
Shinya Kitaoka 120a6e
    newTag = readTextTag();
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case PliTag::PALETTE:
Shinya Kitaoka 120a6e
    newTag = readPaletteTag();
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case PliTag::PALETTE_WITH_ALPHA:
Shinya Kitaoka 120a6e
    newTag = readPaletteWithAlphaTag();
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case PliTag::THICK_QUADRATIC_CHAIN_GOBJ:
Shinya Kitaoka 120a6e
  case PliTag::THICK_QUADRATIC_LOOP_GOBJ:
Shinya Kitaoka 120a6e
    newTag = readThickQuadraticChainTag(tagType ==
Shinya Kitaoka 120a6e
                                        PliTag::THICK_QUADRATIC_LOOP_GOBJ);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case PliTag::GROUP_GOBJ:
Shinya Kitaoka 120a6e
    newTag = readGroupTag();
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case PliTag::IMAGE_GOBJ:
Shinya Kitaoka 120a6e
    newTag = readImageTag();
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case PliTag::COLOR_NGOBJ:
Shinya Kitaoka 120a6e
    newTag = readColorTag();
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case PliTag::STYLE_NGOBJ:
Shinya Kitaoka 120a6e
    newTag = readStyleTag();
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case PliTag::GEOMETRIC_TRANSFORMATION_GOBJ:
Shinya Kitaoka 120a6e
    newTag = readGeometricTransformationTag();
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case PliTag::DOUBLEPAIR_OBJ:
Shinya Kitaoka 120a6e
    newTag = readDoublePairTag();
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case PliTag::BITMAP_GOBJ:
Shinya Kitaoka 120a6e
    newTag = readBitmapTag();
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case PliTag::INTERSECTION_DATA_GOBJ:
Shinya Kitaoka 120a6e
    newTag = readIntersectionDataTag();
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case PliTag::OUTLINE_OPTIONS_GOBJ:
Shinya Kitaoka 120a6e
    newTag = readOutlineOptionsTag();
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case PliTag::PRECISION_SCALE_GOBJ:
Shinya Kitaoka 120a6e
    newTag = readPrecisionScaleTag();
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case PliTag::END_CNTRL:
Shinya Kitaoka 120a6e
    return 0;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (newTag)
Shinya Kitaoka 120a6e
    return new TagElem(newTag, tagOffset);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    return readTag();
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
/*=====================================================================*/
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
PliTag *ParsedPliImp::findTagFromOffset(UINT tagOffs) {
Shinya Kitaoka 120a6e
  for (TagElem *elem = m_firstTag; elem; elem = elem->m_next)
Shinya Kitaoka 120a6e
    if (elem->m_offset == tagOffs) return elem->m_tag;
Shinya Kitaoka 120a6e
  return NULL;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
/*=====================================================================*/
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
UINT ParsedPliImp::findOffsetFromTag(PliTag *tag) {
Shinya Kitaoka 120a6e
  for (TagElem *elem = m_firstTag; elem; elem = elem->m_next)
Shinya Kitaoka 120a6e
    if (elem->m_tag == tag) return elem->m_offset;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return 0;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
/*=====================================================================*/
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
TagElem *ParsedPliImp::findTag(PliTag *tag) {
Shinya Kitaoka 120a6e
  for (TagElem *elem = m_firstTag; elem; elem = elem->m_next)
Shinya Kitaoka 120a6e
    if (elem->m_tag == tag) return elem;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return NULL;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
/*=====================================================================*/
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
inline void ParsedPliImp::readDinamicData(TUINT32 &val, TUINT32 &bufOffs) {
Shinya Kitaoka 120a6e
  switch (m_currDinamicTypeBytesNum) {
Shinya Kitaoka 120a6e
  case 1:
Shinya Kitaoka 120a6e
    val = m_buf[bufOffs++];
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 2:
Shinya Kitaoka 120a6e
    if (m_isIrixEndian)
Shinya Kitaoka 120a6e
      val = m_buf[bufOffs + 1] | (m_buf[bufOffs] << 8);
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      val = m_buf[bufOffs] | (m_buf[bufOffs + 1] << 8);
Shinya Kitaoka 120a6e
    bufOffs += 2;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 4:
Shinya Kitaoka 120a6e
    if (m_isIrixEndian)
Shinya Kitaoka 120a6e
      val = m_buf[bufOffs + 3] | (m_buf[bufOffs + 2] << 8) |
Shinya Kitaoka 120a6e
            (m_buf[bufOffs + 1] << 16) | (m_buf[bufOffs] << 24);
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      val = m_buf[bufOffs] | (m_buf[bufOffs + 1] << 8) |
Shinya Kitaoka 120a6e
            (m_buf[bufOffs + 2] << 16) | (m_buf[bufOffs + 3] << 24);
Shinya Kitaoka 120a6e
    bufOffs += 4;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  default:
Shinya Kitaoka 120a6e
    assert(false);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Shinya Kitaoka 120a6e
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
inline bool ParsedPliImp::readDinamicData(TINT32 &val, TUINT32 &bufOffs) {
Shinya Kitaoka 120a6e
  bool isNegative = false;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  switch (m_currDinamicTypeBytesNum) {
Shinya Kitaoka 120a6e
  case 1:
Shinya Kitaoka 120a6e
    val = m_buf[bufOffs] & 0x7f;
Shinya Kitaoka 120a6e
    if (m_buf[bufOffs] & 0x80) {
Shinya Kitaoka 120a6e
      val        = -val;
Shinya Kitaoka 120a6e
      isNegative = true;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    bufOffs++;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 2:
Shinya Kitaoka 120a6e
    if (m_isIrixEndian) {
Shinya Kitaoka 120a6e
      val = (m_buf[bufOffs + 1] | (m_buf[bufOffs] << 8)) & 0x7fff;
Shinya Kitaoka 120a6e
      if (m_buf[bufOffs] & 0x80) {
Shinya Kitaoka 120a6e
        val        = -val;
Shinya Kitaoka 120a6e
        isNegative = true;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      val = (m_buf[bufOffs] | (m_buf[bufOffs + 1] << 8)) & 0x7fff;
Shinya Kitaoka 120a6e
      if (m_buf[bufOffs + 1] & 0x80) {
Shinya Kitaoka 120a6e
        val        = -val;
Shinya Kitaoka 120a6e
        isNegative = true;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    bufOffs += 2;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 4:
Shinya Kitaoka 120a6e
    if (m_isIrixEndian) {
Shinya Kitaoka 120a6e
      val = m_buf[bufOffs + 3] | (m_buf[bufOffs + 2] << 8) |
Shinya Kitaoka 120a6e
            (m_buf[bufOffs + 1] << 16) | (m_buf[bufOffs] << 24) & 0x7fffffff;
Shinya Kitaoka 120a6e
      if (m_buf[bufOffs] & 0x80) {
Shinya Kitaoka 120a6e
        val        = -val;
Shinya Kitaoka 120a6e
        isNegative = true;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      val = m_buf[bufOffs] | (m_buf[bufOffs + 1] << 8) |
Shinya Kitaoka 120a6e
            (m_buf[bufOffs + 2] << 16) |
Shinya Kitaoka 120a6e
            (m_buf[bufOffs + 3] << 24) & 0x7fffffff;
Shinya Kitaoka 120a6e
      if (m_buf[bufOffs + 3] & 0x80) {
Shinya Kitaoka 120a6e
        val        = -val;
Shinya Kitaoka 120a6e
        isNegative = true;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    bufOffs += 4;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  default:
Shinya Kitaoka 120a6e
    assert(false);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return isNegative;
Toshihiro Shimizu 890ddd
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
/*=====================================================================*/
Shinya Kitaoka 120a6e
/*=====================================================================*/
Shinya Kitaoka 120a6e
/*=====================================================================*/
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
PliTag *ParsedPliImp::readTextTag() {
Shinya Kitaoka 120a6e
  if (m_tagLength == 0) return new TextTag("");
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return new TextTag(string((char *)m_buf.get(), m_tagLength));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
PliTag *ParsedPliImp::readPaletteTag() {
Shinya Kitaoka 120a6e
  TPixelRGBM32 *plt;
Shinya Kitaoka 120a6e
  TUINT32 numColors = 0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  plt = new TPixelRGBM32[m_tagLength / 3];
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  for (unsigned int i = 0; i < m_tagLength; i += 3, numColors++) {
Shinya Kitaoka 120a6e
    plt[numColors].r = m_buf[i];
Shinya Kitaoka 120a6e
    plt[numColors].g = m_buf[i + 1];
Shinya Kitaoka 120a6e
    plt[numColors].b = m_buf[i + 2];
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  PaletteTag *tag = new PaletteTag(numColors, plt);
Toshihiro Shimizu 890ddd
Campbell Barton 87094d
  delete[] plt;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return tag;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
PliTag *ParsedPliImp::readPaletteWithAlphaTag() {
Shinya Kitaoka 120a6e
  TPixelRGBM32 *plt;
Shinya Kitaoka 120a6e
  TUINT32 numColors = 0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  plt = new TPixelRGBM32[m_tagLength / 4];
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  for (unsigned int i = 0; i < m_tagLength; i += 4, numColors++) {
Shinya Kitaoka 120a6e
    plt[numColors].r = m_buf[i];
Shinya Kitaoka 120a6e
    plt[numColors].g = m_buf[i + 1];
Shinya Kitaoka 120a6e
    plt[numColors].b = m_buf[i + 2];
Shinya Kitaoka 120a6e
    plt[numColors].m = m_buf[i + 3];
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  PaletteWithAlphaTag *tag = new PaletteWithAlphaTag(numColors, plt);
Toshihiro Shimizu 890ddd
Campbell Barton 87094d
  delete[] plt;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return tag;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
PliTag *ParsedPliImp::readThickQuadraticChainTag(bool isLoop) {
Shinya Kitaoka 120a6e
  TThickPoint p;
Shinya Kitaoka 120a6e
  TUINT32 bufOffs = 0;
Shinya Kitaoka 120a6e
  double dx1, dy1, dx2, dy2;
Shinya Kitaoka 120a6e
  TINT32 d;
Shinya Kitaoka 120a6e
  TUINT32 numQuadratics = 0;
Shinya Kitaoka 120a6e
  double scale;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool newThicknessWriteMethod =
Shinya Kitaoka 120a6e
      ((m_majorVersionNumber == 5 && m_minorVersionNumber >= 7) ||
Shinya Kitaoka 120a6e
       (m_majorVersionNumber > 5));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  scale = 1.0 / (double)m_precisionScale;
Shinya Kitaoka 120a6e
  int maxThickness;
Shinya Kitaoka 120a6e
  if (newThicknessWriteMethod)
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    maxThickness = m_buf[bufOffs++];
Shinya Kitaoka 120a6e
    m_thickRatio = maxThickness / 255.0;
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    maxThickness = (int)m_maxThickness;
Shinya Kitaoka 120a6e
    assert(m_thickRatio != 0);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TINT32 val;
Shinya Kitaoka 120a6e
  readDinamicData(val, bufOffs);
Shinya Kitaoka 120a6e
  p.x = scale * val;
Shinya Kitaoka 120a6e
  readDinamicData(val, bufOffs);
Shinya Kitaoka 120a6e
  p.y = scale * val;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  p.thick = m_buf[bufOffs++] * m_thickRatio;
Shinya Kitaoka 120a6e
  if (newThicknessWriteMethod)
Shinya Kitaoka 120a6e
    numQuadratics = (m_tagLength - 2 * m_currDinamicTypeBytesNum - 1 - 1) /
Shinya Kitaoka 120a6e
                    (4 * m_currDinamicTypeBytesNum + 2);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    numQuadratics = (m_tagLength - 2 * m_currDinamicTypeBytesNum - 1) /
Shinya Kitaoka 120a6e
                    (4 * m_currDinamicTypeBytesNum + 3);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  std::unique_ptr<tthickquadratic[]> quadratic(</tthickquadratic[]>
Shinya Kitaoka 120a6e
      new TThickQuadratic[numQuadratics]);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  for (unsigned int i = 0; i < numQuadratics; i++) {
Shinya Kitaoka 120a6e
    quadratic[i].setThickP0(p);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    readDinamicData(d, bufOffs);
Shinya Kitaoka 120a6e
    dx1 = scale * d;
Shinya Kitaoka 120a6e
    readDinamicData(d, bufOffs);
Shinya Kitaoka 120a6e
    dy1 = scale * d;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (newThicknessWriteMethod)
Shinya Kitaoka 120a6e
      p.thick = m_buf[bufOffs++] * m_thickRatio;
Shinya Kitaoka 120a6e
    else {
Shinya Kitaoka 120a6e
      if (m_isIrixEndian)
Shinya Kitaoka 120a6e
        p.thick =
Shinya Kitaoka 120a6e
            complement2((USHORT)(m_buf[bufOffs + 1] | (m_buf[bufOffs] << 8))) *
Shinya Kitaoka 120a6e
            m_thickRatio;
Shinya Kitaoka 120a6e
      else
Shinya Kitaoka 120a6e
        p.thick =
Shinya Kitaoka 120a6e
            complement2((USHORT)(m_buf[bufOffs] | (m_buf[bufOffs + 1] << 8))) *
Shinya Kitaoka 120a6e
            m_thickRatio;
Shinya Kitaoka 120a6e
      bufOffs += 2;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    readDinamicData(d, bufOffs);
Shinya Kitaoka 120a6e
    dx2 = scale * d;
Shinya Kitaoka 120a6e
    readDinamicData(d, bufOffs);
Shinya Kitaoka 120a6e
    dy2 = scale * d;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (dx1 == 0 && dy1 == 0)  // p0==p1, or p1==p2  creates problems (in the
Shinya Kitaoka 120a6e
                               // increasecontrolpoints for example) I slightly
Shinya Kitaoka 120a6e
                               // move it...
Shinya Kitaoka 120a6e
    {
Shinya Kitaoka 120a6e
      if (dx2 != 0 || dy2 != 0) {
Shinya Kitaoka 120a6e
        dx1 = 0.001 * dx2;
Shinya Kitaoka 120a6e
        dx2 = 0.999 * dx2;
Shinya Kitaoka 120a6e
        dy1 = 0.001 * dy2;
Shinya Kitaoka 120a6e
        dy2 = 0.999 * dy2;
Shinya Kitaoka 120a6e
        assert(dx1 != 0 || dy1 != 0);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    } else if (dx2 == 0 && dy2 == 0) {
Shinya Kitaoka 120a6e
      if (dx1 != 0 || dy1 != 0) {
Shinya Kitaoka 120a6e
        dx2 = 0.001 * dx1;
Shinya Kitaoka 120a6e
        dx1 = 0.999 * dx1;
Shinya Kitaoka 120a6e
        dy2 = 0.001 * dy1;
Shinya Kitaoka 120a6e
        dy1 = 0.999 * dy1;
Shinya Kitaoka 120a6e
        assert(dx2 != 0 || dy2 != 0);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    p.x += dx1;
Shinya Kitaoka 120a6e
    p.y += dy1;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    quadratic[i].setThickP1(p);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    p.thick = m_buf[bufOffs++] * m_thickRatio;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    p.x += dx2;
Shinya Kitaoka 120a6e
    p.y += dy2;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    quadratic[i].setThickP2(p);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  ThickQuadraticChainTag *tag = new ThickQuadraticChainTag();
Shinya Kitaoka 120a6e
  tag->m_numCurves            = numQuadratics;
Shinya Kitaoka 120a6e
  tag->m_curve                = std::move(quadratic);
Shinya Kitaoka 120a6e
  tag->m_isLoop               = isLoop;
Shinya Kitaoka 120a6e
  tag->m_maxThickness         = maxThickness;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return tag;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
PliTag *ParsedPliImp::readGroupTag() {
Shinya Kitaoka 120a6e
  TUINT32 bufOffs = 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  UCHAR type = m_buf[bufOffs++];
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  assert(type < GroupTag::TYPE_HOW_MANY);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TUINT32 numObjects = (m_tagLength - 1) / m_currDinamicTypeBytesNum;
Shinya Kitaoka 120a6e
  std::unique_ptr<pliobjecttag *[]=""> object(new PliObjectTag *[numObjects]);</pliobjecttag>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  std::unique_ptr<tuint32[]> tagOffs(new TUINT32[numObjects]);</tuint32[]>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  for (TUINT32 i = 0; i < numObjects; i++) {
Shinya Kitaoka 120a6e
    readDinamicData(tagOffs[i], bufOffs);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TagElem *elem;
Shinya Kitaoka 120a6e
  for (TUINT32 i = 0; i < numObjects; i++)
Shinya Kitaoka 120a6e
    while (!(object[i] = (PliObjectTag *)findTagFromOffset(tagOffs[i])))
Shinya Kitaoka 120a6e
      if ((elem = readTag()))
Shinya Kitaoka 120a6e
        addTag(*elem);
Shinya Kitaoka 120a6e
      else
Shinya Kitaoka 120a6e
        assert(false);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  std::unique_ptr<grouptag> tag(new GroupTag());</grouptag>
Shinya Kitaoka 120a6e
  tag->m_type       = type;
Shinya Kitaoka 120a6e
  tag->m_numObjects = numObjects;
Shinya Kitaoka 120a6e
  tag->m_object     = std::move(object);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return tag.release();
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
/*=====================================================================*/
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
PliTag *ParsedPliImp::readColorTag() {
Shinya Kitaoka 120a6e
  ColorTag::styleType style;
Shinya Kitaoka 120a6e
  ColorTag::attributeType attribute;
Shinya Kitaoka 120a6e
  TUINT32 bufOffs = 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  style     = (ColorTag::styleType)m_buf[bufOffs++];
Shinya Kitaoka 120a6e
  attribute = (ColorTag::attributeType)m_buf[bufOffs++];
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  assert(style < ColorTag::STYLE_HOW_MANY);
Shinya Kitaoka 120a6e
  assert(attribute < ColorTag::ATTRIBUTE_HOW_MANY);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TUINT32 numColors = (m_tagLength - 2) / m_currDinamicTypeBytesNum;
Shinya Kitaoka 120a6e
  std::unique_ptr<tuint32[]> colorArray(new TUINT32[numColors]);</tuint32[]>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  for (unsigned int i = 0; i < numColors; i++) {
Shinya Kitaoka 120a6e
    TUINT32 color;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    readDinamicData(color, bufOffs);
Shinya Kitaoka 120a6e
    colorArray[i] = color;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  std::unique_ptr<colortag> tag(</colortag>
Shinya Kitaoka 120a6e
      new ColorTag(style, attribute, numColors, std::move(colorArray)));
Shinya Kitaoka 120a6e
  return tag.release();
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
PliTag *ParsedPliImp::readStyleTag() {
Shinya Kitaoka 120a6e
  std::vector<tstyleparam> paramArray;</tstyleparam>
Shinya Kitaoka 120a6e
  TUINT32 bufOffs = 0;
MCCCS a0ce32
  int length      = m_tagLength;
Shinya Kitaoka 120a6e
  UINT i;
Shinya Kitaoka 120a6e
  USHORT id        = 0;
Shinya Kitaoka 120a6e
  USHORT pageIndex = 0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  UCHAR currDinamicTypeBytesNumSaved = m_currDinamicTypeBytesNum;
Shinya Kitaoka 120a6e
  m_currDinamicTypeBytesNum          = 2;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  readUShortData(id, bufOffs);
MCCCS a0ce32
  length -= 2;
Shinya Kitaoka 120a6e
  if (m_majorVersionNumber > 5 ||
Shinya Kitaoka 120a6e
      (m_majorVersionNumber == 5 && m_minorVersionNumber >= 6)) {
Shinya Kitaoka 120a6e
    readUShortData(pageIndex, bufOffs);
MCCCS a0ce32
    length -= 2;
Shinya Kitaoka 120a6e
  }
MCCCS a0ce32
  while (length > 0) {
Shinya Kitaoka 120a6e
    TStyleParam param;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    param.m_type = (enum TStyleParam::Type)m_buf[bufOffs++];
MCCCS a0ce32
    length--;
Shinya Kitaoka 120a6e
    switch (param.m_type) {
Shinya Kitaoka 120a6e
    case TStyleParam::SP_BYTE:
Shinya Kitaoka 120a6e
      param.m_numericVal = m_buf[bufOffs++];
MCCCS a0ce32
      length--;
Shinya Kitaoka 120a6e
      break;
Shinya Kitaoka 120a6e
    case TStyleParam::SP_USHORT: {
Shinya Kitaoka 120a6e
      USHORT val;
Shinya Kitaoka 120a6e
      readUShortData(val, bufOffs);
Shinya Kitaoka 120a6e
      param.m_numericVal = val;
MCCCS a0ce32
      length -= 2;
Shinya Kitaoka 120a6e
      break;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    case TStyleParam::SP_INT:
Shinya Kitaoka 120a6e
    case TStyleParam::SP_DOUBLE:
Shinya Kitaoka 120a6e
      readFloatData(param.m_numericVal, bufOffs);
MCCCS a0ce32
      length -= 4;
Shinya Kitaoka 120a6e
      break;
Shinya Kitaoka 120a6e
    case TStyleParam::SP_RASTER:
MCCCS a0ce32
      length -= readRasterData(param.m_r, bufOffs);
Shinya Kitaoka 120a6e
      break;
Shinya Kitaoka 120a6e
    case TStyleParam::SP_STRING: {
Shinya Kitaoka 120a6e
      USHORT strLen;
Shinya Kitaoka 120a6e
      readUShortData(strLen, bufOffs);
Shinya Kitaoka 120a6e
      // bufOffs+=2;
Shinya Kitaoka 120a6e
      param.m_string = "";
Shinya Kitaoka 120a6e
      for (i = 0; i < strLen; i++) {
Shinya Kitaoka 120a6e
        param.m_string.append(1, m_buf[bufOffs++]);
Shinya Kitaoka 120a6e
      }
MCCCS a0ce32
      length -= strLen + sizeof(USHORT);
Shinya Kitaoka 120a6e
      break;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    default:
Shinya Kitaoka 120a6e
      assert(false);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    paramArray.push_back(param);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int paramArraySize = paramArray.size();
Shinya Kitaoka 120a6e
  StyleTag *tag =
Shinya Kitaoka 120a6e
      new StyleTag(id, pageIndex, paramArraySize,
Shinya Kitaoka 120a6e
                   (paramArraySize > 0) ? paramArray.data() : nullptr);
Shinya Kitaoka 120a6e
  m_currDinamicTypeBytesNum = currDinamicTypeBytesNumSaved;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return tag;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
PliTag *ParsedPliImp::readOutlineOptionsTag() {
Shinya Kitaoka 120a6e
  TUINT32 bufOffs = 0;
Shinya Kitaoka 120a6e
  TINT32 d;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  const double scale = 0.001;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Read OutlineOptions
Shinya Kitaoka 120a6e
  int capStyle, joinStyle;
Shinya Kitaoka 120a6e
  double miterLower, miterUpper;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  capStyle  = m_buf[bufOffs++];
Shinya Kitaoka 120a6e
  joinStyle = m_buf[bufOffs++];
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  readDinamicData(d, bufOffs);
Shinya Kitaoka 120a6e
  miterLower = scale * d;
Shinya Kitaoka 120a6e
  readDinamicData(d, bufOffs);
Shinya Kitaoka 120a6e
  miterUpper = scale * d;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return new StrokeOutlineOptionsTag(
Shinya Kitaoka 120a6e
      TStroke::OutlineOptions(capStyle, joinStyle, miterLower, miterUpper));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
PliTag *ParsedPliImp::readPrecisionScaleTag() {
Shinya Kitaoka 120a6e
  TUINT32 bufOffs = 0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TINT32 d;
Shinya Kitaoka 120a6e
  readDinamicData(d, bufOffs);
Shinya Kitaoka 120a6e
  m_precisionScale = d;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return new PrecisionScaleTag(m_precisionScale);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ParsedPliImp::readFloatData(double &val, TUINT32 &bufOffs) {
Shinya Kitaoka 120a6e
  // UCHAR currDinamicTypeBytesNumSaved = m_currDinamicTypeBytesNum;
Shinya Kitaoka 120a6e
  // m_currDinamicTypeBytesNum = 2;
Shinya Kitaoka 120a6e
  TINT32 valInt;
Shinya Kitaoka 120a6e
  TUINT32 valDec;
Shinya Kitaoka 120a6e
  bool isNegative;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  isNegative = readDinamicData(valInt, bufOffs);
Shinya Kitaoka 120a6e
  readDinamicData(valDec, bufOffs);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  val = valInt + (double)valDec / 65536.0;  // 2^16
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (valInt == 0 && isNegative) val = -val;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // m_currDinamicTypeBytesNum = currDinamicTypeBytesNumSaved;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
UINT ParsedPliImp::readRasterData(TRaster32P &r, TUINT32 &bufOffs) {
Shinya Kitaoka 120a6e
  USHORT lx, ly;
Shinya Kitaoka 120a6e
  readUShortData(lx, bufOffs);
Shinya Kitaoka 120a6e
  readUShortData(ly, bufOffs);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // readUShortData((USHORT&)lx, bufOffs);
Shinya Kitaoka 120a6e
  // readUShortData((USHORT&)ly, bufOffs);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  r.create((int)lx, (int)ly);
Shinya Kitaoka 120a6e
  UINT size = lx * ly * 4;
Shinya Kitaoka 120a6e
  r->lock();
Shinya Kitaoka 120a6e
  memcpy(r->getRawData(), m_buf.get() + bufOffs, size);
Shinya Kitaoka 120a6e
  r->unlock();
Shinya Kitaoka 120a6e
  bufOffs += size;
Shinya Kitaoka 120a6e
  return size + 2 + 2;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
inline void getLongValFromFloat(double val, TINT32 &intVal, TUINT32 &decVal) {
Shinya Kitaoka 120a6e
  intVal              = (TINT32)val;
Shinya Kitaoka 120a6e
  if (val < 0) decVal = (TUINT32)((double)((-val) - (-intVal)) * 65536.0);
Shinya Kitaoka 120a6e
  /*if (intVal<(0x1<<7))
Shinya Kitaoka 120a6e
intVal|=(0x1<<7);
Shinya Kitaoka 120a6e
else if (intVal<(0x1<<15))
Shinya Kitaoka 120a6e
intVal|=(0x1<<15);
Shinya Kitaoka 120a6e
else
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 120a6e
assert(intVal<(0x1<<31));
Shinya Kitaoka 120a6e
intVal|=(0x1<<31);
Toshihiro Shimizu 890ddd
}*/
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    decVal = (TUINT32)((double)(val - intVal) * 65536.0);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ParsedPliImp::writeFloatData(double val) {
Shinya Kitaoka 120a6e
  UCHAR currDinamicTypeBytesNumSaved = m_currDinamicTypeBytesNum;
Shinya Kitaoka 120a6e
  m_currDinamicTypeBytesNum          = 2;
Shinya Kitaoka 120a6e
  TINT32 valInt;
Shinya Kitaoka 120a6e
  TUINT32 valDec;
Shinya Kitaoka 120a6e
  // bool neg=false;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  valInt = (int)val;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (val < 0)
Shinya Kitaoka 120a6e
    valDec = (int)((double)(-val + valInt) * 65536.0);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    valDec = (int)((double)(val - valInt) * 65536.0);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  assert(valInt < (0x1 << 15));
Shinya Kitaoka 120a6e
  assert(valDec < (0x1 << 16));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  writeDinamicData(valInt, val < 0);
Shinya Kitaoka 120a6e
  writeDinamicData(valDec);
Shinya Kitaoka 120a6e
  m_currDinamicTypeBytesNum = currDinamicTypeBytesNumSaved;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
PliTag *ParsedPliImp::readGeometricTransformationTag() {
Shinya Kitaoka 120a6e
  TUINT32 bufOffs = 0;
Shinya Kitaoka 120a6e
  TAffine affine;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  readFloatData(affine.a11, bufOffs);
Shinya Kitaoka 120a6e
  readFloatData(affine.a12, bufOffs);
Shinya Kitaoka 120a6e
  readFloatData(affine.a13, bufOffs);
Shinya Kitaoka 120a6e
  readFloatData(affine.a21, bufOffs);
Shinya Kitaoka 120a6e
  readFloatData(affine.a22, bufOffs);
Shinya Kitaoka 120a6e
  readFloatData(affine.a23, bufOffs);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TUINT32 tagOffs;
Shinya Kitaoka 120a6e
  readDinamicData(tagOffs, bufOffs);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TagElem *elem;
Shinya Kitaoka 120a6e
  PliObjectTag *object = NULL;
Shinya Kitaoka 120a6e
  if (tagOffs != 0)
Shinya Kitaoka 120a6e
    while (!(object = (PliObjectTag *)findTagFromOffset(tagOffs)))
Shinya Kitaoka 120a6e
      if ((elem = readTag()))
Shinya Kitaoka 120a6e
        addTag(*elem);
Shinya Kitaoka 120a6e
      else
Shinya Kitaoka 120a6e
        assert(false);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    m_affine = affine;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  /*int realScale = tround(log10(1.0/m_affine.a11));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
m_affine = TScale(1.0/pow(10.0, realScale));*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  GeometricTransformationTag *tag =
Shinya Kitaoka 120a6e
      new GeometricTransformationTag(affine, (PliGeometricTag *)object);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return tag;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
PliTag *ParsedPliImp::readDoublePairTag() {
Shinya Kitaoka 120a6e
  TUINT32 bufOffs = 0;
Shinya Kitaoka 120a6e
  double first, second;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  readFloatData(first, bufOffs);
Shinya Kitaoka 120a6e
  readFloatData(second, bufOffs);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  DoublePairTag *tag = new DoublePairTag(first, second);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return tag;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ParsedPliImp::readUShortData(USHORT &val, TUINT32 &bufOffs) {
Shinya Kitaoka 120a6e
  if (m_isIrixEndian)
Shinya Kitaoka 120a6e
    val = m_buf[bufOffs + 1] | (m_buf[bufOffs] << 8);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    val = m_buf[bufOffs] | (m_buf[bufOffs + 1] << 8);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bufOffs += 2;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ParsedPliImp::readTUINT32Data(TUINT32 &val, TUINT32 &bufOffs) {
Shinya Kitaoka 120a6e
  if (m_isIrixEndian)
Shinya Kitaoka 120a6e
    val = m_buf[bufOffs + 3] | (m_buf[bufOffs + 2] << 8) |
Shinya Kitaoka 120a6e
          (m_buf[bufOffs + 1] << 16) | (m_buf[bufOffs] << 24);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    val = m_buf[bufOffs] | (m_buf[bufOffs + 1] << 8) |
Shinya Kitaoka 120a6e
          (m_buf[bufOffs + 2] << 16) | (m_buf[bufOffs + 3] << 24);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bufOffs += 4;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
PliTag *ParsedPliImp::readBitmapTag() {
Shinya Kitaoka 120a6e
  USHORT lx, ly;
Shinya Kitaoka 120a6e
  TUINT32 bufOffs = 0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  readUShortData(lx, bufOffs);
Shinya Kitaoka 120a6e
  readUShortData(ly, bufOffs);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TRaster32P r;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  r.create(lx, ly);
Shinya Kitaoka 120a6e
  r->lock();
Shinya Kitaoka 120a6e
  memcpy(r->getRawData(), m_buf.get() + bufOffs, lx * ly * 4);
Shinya Kitaoka 120a6e
  r->unlock();
Shinya Kitaoka 120a6e
  BitmapTag *tag = new BitmapTag(r);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return tag;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
PliTag *ParsedPliImp::readImageTag() {
Shinya Kitaoka 120a6e
  USHORT frame;
Shinya Kitaoka 120a6e
  TUINT32 bufOffs = 0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (m_isIrixEndian)
Shinya Kitaoka 120a6e
    frame = m_buf[bufOffs + 1] | (m_buf[bufOffs] << 8);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    frame = m_buf[bufOffs] | (m_buf[bufOffs + 1] << 8);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bufOffs += 2;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int headerLength = 2;
Shinya Kitaoka 120a6e
  char letter      = 0;
Shinya Kitaoka 120a6e
  if (m_majorVersionNumber > 6 ||
Shinya Kitaoka 120a6e
      (m_majorVersionNumber == 6 && m_minorVersionNumber >= 6)) {
Shinya Kitaoka 120a6e
    letter = (char)m_buf[bufOffs++];
Shinya Kitaoka 120a6e
    ++headerLength;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TUINT32 numObjects = (m_tagLength - headerLength) / m_currDinamicTypeBytesNum;
Shinya Kitaoka 120a6e
  std::unique_ptr<pliobjecttag *[]=""> object(new PliObjectTag *[numObjects]);</pliobjecttag>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  std::unique_ptr<tuint32[]> tagOffs(new TUINT32[numObjects]);</tuint32[]>
Shinya Kitaoka 120a6e
  for (TUINT32 i = 0; i < numObjects; i++) {
Shinya Kitaoka 120a6e
    readDinamicData(tagOffs[i], bufOffs);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TagElem *elem;
Shinya Kitaoka 120a6e
  for (TUINT32 i = 0; i < numObjects; i++)
Shinya Kitaoka 120a6e
    while (!(object[i] = (PliObjectTag *)findTagFromOffset(tagOffs[i])))
Shinya Kitaoka 120a6e
      if ((elem = readTag()))
Shinya Kitaoka 120a6e
        addTag(*elem);
Shinya Kitaoka 120a6e
      else
Shinya Kitaoka 120a6e
        assert(false);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  std::unique_ptr<imagetag[]> tag(</imagetag[]>
Shinya Kitaoka 120a6e
      new ImageTag(TFrameId(frame, letter), numObjects, std::move(object)));
Shinya Kitaoka 120a6e
  return tag.release();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
const TSolidColorStyle ConstStyle(TPixel32::Red);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
inline double doubleFromUlong(TUINT32 q) {
Shinya Kitaoka 120a6e
  assert((q & 0X00000001) == 0);
Shinya Kitaoka 120a6e
  TUINT32 l[2];
Toshihiro Shimizu 890ddd
#if TNZ_LITTLE_ENDIAN
Shinya Kitaoka 120a6e
  l[1] = 0x3FF00000 | (q >> 12);
Shinya Kitaoka 120a6e
  l[0] = (q & 0xFFE) << 20;
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
  l[0]             = 0x3FF00000 | (q >> 12);
Shinya Kitaoka 120a6e
  l[1]             = (q & 0xFFE) << 20;
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return *(double *)l - 1;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
// vedi commento sulla write per chiarimenti!!
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
inline double truncate(double x) {
Shinya Kitaoka 120a6e
  x += 1.0;
Shinya Kitaoka 120a6e
  TUINT32 *l = (TUINT32 *)&x;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#if TNZ_LITTLE_ENDIAN
Shinya Kitaoka 120a6e
  l[0] &= 0xFFE00000;
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
  l[1] &= 0xFFE00000;
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return x - 1.0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
PliTag *ParsedPliImp::readIntersectionDataTag() {
Shinya Kitaoka 120a6e
  TUINT32 bufOffs = 0;
Shinya Kitaoka 120a6e
  TUINT32 branchCount;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  readTUINT32Data(branchCount, bufOffs);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  std::unique_ptr<intersectionbranch[]> branchArray(</intersectionbranch[]>
Shinya Kitaoka 120a6e
      new IntersectionBranch[branchCount]);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  UINT i;
Shinya Kitaoka 120a6e
  for (i = 0; i < branchCount; i++) {
Shinya Kitaoka 120a6e
    TINT32 currInter;
Shinya Kitaoka 120a6e
    readDinamicData((TINT32 &)branchArray[i].m_strokeIndex, bufOffs);
Shinya Kitaoka 120a6e
    readDinamicData(currInter, bufOffs);
Shinya Kitaoka 120a6e
    readDinamicData((TUINT32 &)branchArray[i].m_nextBranch, bufOffs);
Shinya Kitaoka 120a6e
    USHORT style;
Shinya Kitaoka 120a6e
    readUShortData(style, bufOffs);
Shinya Kitaoka 120a6e
    branchArray[i].m_style = style;
Shinya Kitaoka 120a6e
    /*
Shinya Kitaoka 120a6e
*/
Shinya Kitaoka 120a6e
    if (m_buf[bufOffs] & 0x80)  // in un numero double tra 0 e 1, il bit piu'
Shinya Kitaoka 120a6e
                                // significativo e' sempre 0
Shinya Kitaoka 120a6e
    // sfrutto questo bit; se e' 1, vuol dire che il valore e' 0.0 o 1.0 in un
Shinya Kitaoka 120a6e
    // singolo byte
Shinya Kitaoka 120a6e
    {
Shinya Kitaoka 120a6e
      branchArray[i].m_w = (m_buf[bufOffs] & 0x1) ? 1.0 : 0.0;
Shinya Kitaoka 120a6e
      bufOffs++;
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      TUINT32 hi, lo;
Shinya Kitaoka 120a6e
      hi = m_buf[bufOffs + 3] | (m_buf[bufOffs + 2] << 8) |
Shinya Kitaoka 120a6e
           (m_buf[bufOffs + 1] << 16) | (m_buf[bufOffs] << 24);
Shinya Kitaoka 120a6e
      bufOffs += 4;
Shinya Kitaoka 120a6e
      readTUINT32Data(lo, bufOffs);
Shinya Kitaoka 120a6e
      // readTUINT32Data(hi, bufOffs);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      branchArray[i].m_w = doubleFromUlong1(hi, lo);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (currInter < 0) {
Shinya Kitaoka 120a6e
      branchArray[i].m_currInter  = -currInter - 1;
Shinya Kitaoka 120a6e
      branchArray[i].m_gettingOut = false;
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      branchArray[i].m_currInter  = currInter - 1;
Shinya Kitaoka 120a6e
      branchArray[i].m_gettingOut = true;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  IntersectionDataTag *tag = new IntersectionDataTag();
Shinya Kitaoka 120a6e
  tag->m_branchCount       = branchCount;
Shinya Kitaoka 120a6e
  tag->m_branchArray       = std::move(branchArray);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return tag;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
/*=====================================================================*/
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
bool ParsedPliImp::addTag(PliTag *tagPtr, bool addFront) {
Shinya Kitaoka 120a6e
  TagElem *_tag = new TagElem(tagPtr, 0);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  assert(tagPtr->m_type);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (!m_firstTag) {
Shinya Kitaoka 120a6e
    m_firstTag = m_lastTag = _tag;
Shinya Kitaoka 120a6e
  } else if (addFront) {
Shinya Kitaoka 120a6e
    _tag->m_next = m_firstTag;
Shinya Kitaoka 120a6e
    m_firstTag   = _tag;
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    m_lastTag->m_next = _tag;
Shinya Kitaoka 120a6e
    m_lastTag         = m_lastTag->m_next;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return true;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
/*=====================================================================*/
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
bool ParsedPliImp::addTag(const TagElem &elem, bool addFront) {
Shinya Kitaoka 120a6e
  TagElem *_tag = new TagElem(elem);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (!m_firstTag) {
Shinya Kitaoka 120a6e
    m_firstTag = m_lastTag = _tag;
Shinya Kitaoka 120a6e
  } else if (addFront) {
Shinya Kitaoka 120a6e
    _tag->m_next = m_firstTag;
Shinya Kitaoka 120a6e
    m_firstTag   = _tag;
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    m_lastTag->m_next = _tag;
Shinya Kitaoka 120a6e
    m_lastTag         = m_lastTag->m_next;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return true;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
/*=====================================================================*/
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void ParsedPliImp::writeTag(TagElem *elem) {
Shinya Kitaoka 120a6e
  if (elem->m_offset != 0)  // already written
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  switch (elem->m_tag->m_type) {
Shinya Kitaoka 120a6e
  case PliTag::TEXT:
Shinya Kitaoka 120a6e
    elem->m_offset = writeTextTag((TextTag *)elem->m_tag);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case PliTag::PALETTE:
Shinya Kitaoka 120a6e
    elem->m_offset = writePaletteTag((PaletteTag *)elem->m_tag);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case PliTag::PALETTE_WITH_ALPHA:
Shinya Kitaoka 120a6e
    elem->m_offset =
Shinya Kitaoka 120a6e
        writePaletteWithAlphaTag((PaletteWithAlphaTag *)elem->m_tag);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case PliTag::THICK_QUADRATIC_CHAIN_GOBJ:
Shinya Kitaoka 120a6e
    elem->m_offset =
Shinya Kitaoka 120a6e
        writeThickQuadraticChainTag((ThickQuadraticChainTag *)elem->m_tag);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case PliTag::GROUP_GOBJ:
Shinya Kitaoka 120a6e
    elem->m_offset = writeGroupTag((GroupTag *)elem->m_tag);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case PliTag::IMAGE_GOBJ:
Shinya Kitaoka 120a6e
    elem->m_offset = writeImageTag((ImageTag *)elem->m_tag);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case PliTag::COLOR_NGOBJ:
Shinya Kitaoka 120a6e
    elem->m_offset = writeColorTag((ColorTag *)elem->m_tag);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case PliTag::STYLE_NGOBJ:
Shinya Kitaoka 120a6e
    elem->m_offset = writeStyleTag((StyleTag *)elem->m_tag);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case PliTag::GEOMETRIC_TRANSFORMATION_GOBJ:
Shinya Kitaoka 120a6e
    elem->m_offset = writeGeometricTransformationTag(
Shinya Kitaoka 120a6e
        (GeometricTransformationTag *)elem->m_tag);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case PliTag::DOUBLEPAIR_OBJ:
Shinya Kitaoka 120a6e
    elem->m_offset = writeDoublePairTag((DoublePairTag *)elem->m_tag);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case PliTag::BITMAP_GOBJ:
Shinya Kitaoka 120a6e
    elem->m_offset = writeBitmapTag((BitmapTag *)elem->m_tag);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case PliTag::INTERSECTION_DATA_GOBJ:
Shinya Kitaoka 120a6e
    elem->m_offset =
Shinya Kitaoka 120a6e
        writeIntersectionDataTag((IntersectionDataTag *)elem->m_tag);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case PliTag::OUTLINE_OPTIONS_GOBJ:
Shinya Kitaoka 120a6e
    elem->m_offset =
Shinya Kitaoka 120a6e
        writeOutlineOptionsTag((StrokeOutlineOptionsTag *)elem->m_tag);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case PliTag::PRECISION_SCALE_GOBJ:
Shinya Kitaoka 120a6e
    elem->m_offset = writePrecisionScaleTag((PrecisionScaleTag *)elem->m_tag);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  default:
Shinya Kitaoka 120a6e
    assert(false);
Shinya Kitaoka 120a6e
    // m_error = UNKNOWN_TAG;
Shinya Kitaoka 120a6e
    ;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
/*=====================================================================*/
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
inline void ParsedPliImp::setDinamicTypeBytesNum(int minval, int maxval) {
Shinya Kitaoka 120a6e
  assert(m_oChan);
Shinya Kitaoka 120a6e
  if (maxval > 32767 || minval < -32767) {
Shinya Kitaoka 120a6e
    if (m_currDinamicTypeBytesNum != 4) {
Shinya Kitaoka 120a6e
      m_currDinamicTypeBytesNum = 4;
Shinya Kitaoka 120a6e
      *m_oChan << (UCHAR)PliTag::SET_DATA_32_CNTRL;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  } else if (maxval > 127 || minval < -127) {
Shinya Kitaoka 120a6e
    if (m_currDinamicTypeBytesNum != 2) {
Shinya Kitaoka 120a6e
      m_currDinamicTypeBytesNum = 2;
Shinya Kitaoka 120a6e
      *m_oChan << (UCHAR)PliTag::SET_DATA_16_CNTRL;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  } else if (m_currDinamicTypeBytesNum != 1) {
Shinya Kitaoka 120a6e
    m_currDinamicTypeBytesNum = 1;
Shinya Kitaoka 120a6e
    *m_oChan << (UCHAR)PliTag::SET_DATA_8_CNTRL;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
inline void ParsedPliImp::writeDinamicData(TUINT32 val) {
Shinya Kitaoka 120a6e
  assert(m_oChan);
Shinya Kitaoka 120a6e
  switch (m_currDinamicTypeBytesNum) {
Shinya Kitaoka 120a6e
  case 1:
Shinya Kitaoka 120a6e
    *m_oChan << (UCHAR)val;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 2:
Shinya Kitaoka 120a6e
    *m_oChan << (USHORT)val;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 4:
Shinya Kitaoka 120a6e
    *m_oChan << (TUINT32)val;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  default:
Shinya Kitaoka 120a6e
    assert(false);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
/*=====================================================================*/
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
inline void ParsedPliImp::writeDinamicData(TINT32 val,
Shinya Kitaoka 120a6e
                                           bool isNegative = false) {
Shinya Kitaoka 120a6e
  assert(m_oChan);
Shinya Kitaoka 120a6e
  switch (m_currDinamicTypeBytesNum) {
Shinya Kitaoka 120a6e
  case 1:
Shinya Kitaoka 120a6e
    *m_oChan << complement1((char)val, isNegative);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 2:
Shinya Kitaoka 120a6e
    *m_oChan << complement1((short)val, isNegative);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 4:
Shinya Kitaoka 120a6e
    *m_oChan << complement1(val, isNegative);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  default:
Shinya Kitaoka 120a6e
    assert(false);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TUINT32 ParsedPliImp::writeTagHeader(UCHAR type, UINT tagLength) {
Shinya Kitaoka 120a6e
  assert(m_oChan);
Shinya Kitaoka 120a6e
  TUINT32 offset = m_oChan->tellp();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  assert((type & 0xc0) == 0x0);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (tagLength == 0)
Shinya Kitaoka 120a6e
    *m_oChan << type;
Shinya Kitaoka 120a6e
  else if (tagLength < 256) {
Shinya Kitaoka 120a6e
    *m_oChan << (UCHAR)(type | (0x1 << 6));
Shinya Kitaoka 120a6e
    *m_oChan << (UCHAR)tagLength;
Shinya Kitaoka 120a6e
  } else if (tagLength < 65535) {
Shinya Kitaoka 120a6e
    *m_oChan << (UCHAR)(type | (0x2 << 6));
Shinya Kitaoka 120a6e
    *m_oChan << (USHORT)tagLength;
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    *m_oChan << (UCHAR)(type | (0x3 << 6));
Shinya Kitaoka 120a6e
    *m_oChan << (TUINT32)tagLength;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return offset;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TUINT32 ParsedPliImp::writeTextTag(TextTag *tag) {
Shinya Kitaoka 120a6e
  assert(m_oChan);
Shinya Kitaoka 120a6e
  int offset, tagLength = tag->m_text.length();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  offset = (int)writeTagHeader((UCHAR)PliTag::TEXT, tagLength);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  for (int i = 0; i < tagLength; i++) *m_oChan << tag->m_text[i];
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return offset;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TUINT32 ParsedPliImp::writePaletteTag(PaletteTag *tag) {
Shinya Kitaoka 120a6e
  assert(m_oChan);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int offset, tagLength = (int)(tag->m_numColors * 3);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  offset = (int)writeTagHeader((UCHAR)PliTag::PALETTE, tagLength);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  for (unsigned int i = 0; i < tag->m_numColors; i++) {
Shinya Kitaoka 120a6e
    *m_oChan << tag->m_color[i].r;
Shinya Kitaoka 120a6e
    *m_oChan << tag->m_color[i].g;
Shinya Kitaoka 120a6e
    *m_oChan << tag->m_color[i].b;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return offset;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TUINT32 ParsedPliImp::writePaletteWithAlphaTag(PaletteWithAlphaTag *tag) {
Shinya Kitaoka 120a6e
  assert(m_oChan);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int offset, tagLength = (int)(tag->m_numColors * 4);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  offset = (int)writeTagHeader((UCHAR)PliTag::PALETTE_WITH_ALPHA, tagLength);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  for (unsigned int i = 0; i < tag->m_numColors; i++) {
Shinya Kitaoka 120a6e
    *m_oChan << tag->m_color[i].r;
Shinya Kitaoka 120a6e
    *m_oChan << tag->m_color[i].g;
Shinya Kitaoka 120a6e
    *m_oChan << tag->m_color[i].b;
Shinya Kitaoka 120a6e
    *m_oChan << tag->m_color[i].m;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return offset;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
#define SET_MINMAX                                                             \
Shinya Kitaoka 120a6e
  if (p.x < minval) minval = (int)p.x;                                         \
Shinya Kitaoka 120a6e
  if (p.y < minval) minval = (int)p.y;                                         \
Shinya Kitaoka 120a6e
  if (p.x > maxval) maxval = (int)p.x;                                         \
Shinya Kitaoka 120a6e
  if (p.y > maxval) maxval = (int)p.y;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
inline void ParsedPliImp::WRITE_UCHAR_FROM_DOUBLE(double dval) {
Shinya Kitaoka 120a6e
  assert(m_oChan);
Shinya Kitaoka 120a6e
  int ival             = tround(dval);
Shinya Kitaoka 120a6e
  if (ival > 255) ival = 255;
Shinya Kitaoka 120a6e
  assert(ival >= 0);
Shinya Kitaoka 120a6e
  *m_oChan << (UCHAR)ival;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
inline void ParsedPliImp::WRITE_SHORT_FROM_DOUBLE(double dval) {
Shinya Kitaoka 120a6e
  assert(m_oChan);
Shinya Kitaoka 120a6e
  int ival = (int)(dval);
Shinya Kitaoka 120a6e
  assert(ival >= -32768 && ival < 32768);
Shinya Kitaoka 120a6e
  *m_oChan << complement1((short)ival);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TUINT32 ParsedPliImp::writeThickQuadraticChainTag(ThickQuadraticChainTag *tag) {
Shinya Kitaoka 120a6e
  assert(m_oChan);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int maxval = -(std::numeric_limits<int>::max)(),</int>
Shinya Kitaoka 120a6e
      minval = (std::numeric_limits<int>::max)();</int>
Shinya Kitaoka 120a6e
  TPointD p;
Shinya Kitaoka 120a6e
  double scale;
Shinya Kitaoka 120a6e
  int i;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  assert(m_majorVersionNumber > 5 ||
Shinya Kitaoka 120a6e
         (m_majorVersionNumber == 5 && m_minorVersionNumber >= 5));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  scale = m_precisionScale;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  /*for ( i=0; i<tag->m_numCurves; i++)</tag->
Shinya Kitaoka 120a6e
tag->m_curve[i] =  aff*tag->m_curve[i];*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  p = scale * tag->m_curve[0].getP0();
Shinya Kitaoka 120a6e
  SET_MINMAX
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  for (i = 0; i < (int)tag->m_numCurves; i++) {
Shinya Kitaoka 120a6e
    p = scale * (tag->m_curve[i].getP1() - tag->m_curve[i].getP0());
Shinya Kitaoka 120a6e
    SET_MINMAX
Shinya Kitaoka 120a6e
    p = scale * (tag->m_curve[i].getP2() - tag->m_curve[i].getP1());
Shinya Kitaoka 120a6e
    SET_MINMAX
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  setDinamicTypeBytesNum(minval, maxval);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int tagLength =
Shinya Kitaoka 120a6e
      (int)(2 * (2 * tag->m_numCurves + 1) * m_currDinamicTypeBytesNum + 1 + 1 +
Shinya Kitaoka 120a6e
            2 * tag->m_numCurves);
Shinya Kitaoka 120a6e
  int offset;
Shinya Kitaoka 120a6e
  if (tag->m_isLoop)
Shinya Kitaoka 120a6e
    offset = (int)writeTagHeader((UCHAR)PliTag::THICK_QUADRATIC_LOOP_GOBJ,
Shinya Kitaoka 120a6e
                                 tagLength);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    offset = (int)writeTagHeader((UCHAR)PliTag::THICK_QUADRATIC_CHAIN_GOBJ,
Shinya Kitaoka 120a6e
                                 tagLength);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // assert(scale*tag->m_curve[0].getThickP0().x ==
Shinya Kitaoka 120a6e
  // (double)(TINT32)(scale*tag->m_curve[0].getThickP0().x));
Shinya Kitaoka 120a6e
  // assert(scale*tag->m_curve[0].getThickP0().y ==
Shinya Kitaoka 120a6e
  // (double)(TINT32)(scale*tag->m_curve[0].getThickP0().y));
Shinya Kitaoka 120a6e
  double thickRatio = tag->m_maxThickness / 255.0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  assert(tag->m_maxThickness <= 255);
Shinya Kitaoka 120a6e
  assert(tag->m_maxThickness > 0);
Shinya Kitaoka 120a6e
  UCHAR maxThickness = (UCHAR)(tceil(tag->m_maxThickness));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  *m_oChan << maxThickness;
Shinya Kitaoka 120a6e
  thickRatio = maxThickness / 255.0;
Shinya Kitaoka 120a6e
  writeDinamicData((TINT32)(scale * tag->m_curve[0].getThickP0().x));
Shinya Kitaoka 120a6e
  writeDinamicData((TINT32)(scale * tag->m_curve[0].getThickP0().y));
Shinya Kitaoka 120a6e
  double thick = tag->m_curve[0].getThickP0().thick / thickRatio;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  WRITE_UCHAR_FROM_DOUBLE(thick < 0 ? 0 : thick);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  for (i = 0; i < (int)tag->m_numCurves; i++) {
Shinya Kitaoka 120a6e
    TPoint dp =
Shinya Kitaoka 120a6e
        convert(scale * (tag->m_curve[i].getP1() - tag->m_curve[i].getP0()));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    assert(dp.x == (double)(TINT32)dp.x);
Shinya Kitaoka 120a6e
    assert(dp.y == (double)(TINT32)dp.y);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    writeDinamicData((TINT32)dp.x);
Shinya Kitaoka 120a6e
    writeDinamicData((TINT32)dp.y);
Shinya Kitaoka 120a6e
    thick = tag->m_curve[i].getThickP1().thick / thickRatio;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    WRITE_UCHAR_FROM_DOUBLE(thick < 0 ? 0 : thick);
Shinya Kitaoka 120a6e
    dp = convert(scale * (tag->m_curve[i].getP2() - tag->m_curve[i].getP1()));
Shinya Kitaoka 120a6e
    writeDinamicData((TINT32)dp.x);
Shinya Kitaoka 120a6e
    writeDinamicData((TINT32)dp.y);
Shinya Kitaoka 120a6e
    thick = tag->m_curve[i].getThickP2().thick / thickRatio;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    WRITE_UCHAR_FROM_DOUBLE(thick < 0 ? 0 : thick);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return offset;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TUINT32 ParsedPliImp::writeGroupTag(GroupTag *tag) {
Shinya Kitaoka 120a6e
  assert(m_oChan);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TUINT32 offset, tagLength;
Shinya Kitaoka 120a6e
  int maxval = 0, minval = 100000;
Shinya Kitaoka 120a6e
  std::vector<tuint32> objectOffset(tag->m_numObjects);</tuint32>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  unsigned int i;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  for (i = 0; i < tag->m_numObjects; i++) {
Shinya Kitaoka 120a6e
    if (!(objectOffset[i] =
Shinya Kitaoka 120a6e
              findOffsetFromTag(tag->m_object[i])))  // the object was not
Shinya Kitaoka 120a6e
                                                     // already written before:
Shinya Kitaoka 120a6e
                                                     // write it now
Shinya Kitaoka 120a6e
    {
Shinya Kitaoka 120a6e
      TagElem elem(tag->m_object[i], 0);
Shinya Kitaoka 120a6e
      writeTag(&elem);
Shinya Kitaoka 120a6e
      objectOffset[i] = elem.m_offset;
Shinya Kitaoka 120a6e
      addTag(elem);
Shinya Kitaoka 120a6e
      elem.m_tag = 0;
Shinya Kitaoka 120a6e
    }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    if (objectOffset[i] < (unsigned int)minval) minval = (int)objectOffset[i];
Shinya Kitaoka 120a6e
    if (objectOffset[i] > (unsigned int)maxval) maxval = (int)objectOffset[i];
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  setDinamicTypeBytesNum(minval, maxval);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  tagLength = tag->m_numObjects * m_currDinamicTypeBytesNum + 1;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  offset = writeTagHeader((UCHAR)PliTag::GROUP_GOBJ, tagLength);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  *m_oChan << tag->m_type;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  for (i = 0; i < tag->m_numObjects; i++) writeDinamicData(objectOffset[i]);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return offset;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TUINT32 ParsedPliImp::writeImageTag(ImageTag *tag) {
Shinya Kitaoka 120a6e
  assert(m_oChan);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TUINT32 *objectOffset, offset, tagLength;
Shinya Kitaoka 120a6e
  int maxval = 0, minval = 100000;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  writeTagHeader((UCHAR)PliTag::IMAGE_BEGIN_GOBJ, 3);
Shinya Kitaoka 120a6e
  *m_oChan << (USHORT)tag->m_numFrame.getNumber();
Shinya Kitaoka 120a6e
  *m_oChan << tag->m_numFrame.getLetter();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_currDinamicTypeBytesNum = 3;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  objectOffset = new TUINT32[tag->m_numObjects];
Shinya Kitaoka 120a6e
  unsigned int i;
Shinya Kitaoka 120a6e
  for (i = 0; i < tag->m_numObjects; i++) {
Shinya Kitaoka 120a6e
    if (!(objectOffset[i] =
Shinya Kitaoka 120a6e
              findOffsetFromTag(tag->m_object[i])))  // the object was not
Shinya Kitaoka 120a6e
                                                     // already written before:
Shinya Kitaoka 120a6e
                                                     // write it now
Shinya Kitaoka 120a6e
    {
Shinya Kitaoka 120a6e
      TagElem elem(tag->m_object[i], 0);
Shinya Kitaoka 120a6e
      writeTag(&elem);
Shinya Kitaoka 120a6e
      objectOffset[i] = elem.m_offset;
Shinya Kitaoka 120a6e
      addTag(elem);
Shinya Kitaoka 120a6e
      elem.m_tag = 0;
Shinya Kitaoka 120a6e
    }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    if (objectOffset[i] < (unsigned int)minval) minval = (int)objectOffset[i];
Shinya Kitaoka 120a6e
    if (objectOffset[i] > (unsigned int)maxval) maxval = (int)objectOffset[i];
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  setDinamicTypeBytesNum(minval, maxval);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  tagLength = tag->m_numObjects * m_currDinamicTypeBytesNum + 3;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  offset = writeTagHeader((UCHAR)PliTag::IMAGE_GOBJ, tagLength);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  *m_oChan << (USHORT)tag->m_numFrame.getNumber();
Shinya Kitaoka 120a6e
  *m_oChan << tag->m_numFrame.getLetter();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  for (i = 0; i < tag->m_numObjects; i++) writeDinamicData(objectOffset[i]);
Toshihiro Shimizu 890ddd
Campbell Barton 87094d
  delete[] objectOffset;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return offset;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
/*struct intersectionBranch
Toshihiro Shimizu 890ddd
  {
Toshihiro Shimizu 890ddd
  int m_strokeIndex;
Toshihiro Shimizu 890ddd
  const TColorStyle* m_style;
Toshihiro Shimizu 890ddd
  double m_w;
Toshihiro Shimizu 890ddd
  UINT currInter;
Toshihiro Shimizu 890ddd
  UINT m_nextBranch;
Toshihiro Shimizu 890ddd
  bool m_gettingOut;
Toshihiro Shimizu 890ddd
  };
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
// per scrivere il valore m_w, molto spesso vale 0 oppure 1;
Shinya Kitaoka 120a6e
// se vale 0, scrivo un bye con valore 0x0;
Shinya Kitaoka 120a6e
// se vale 1, scrivo un bye con valore 0x1;
Toshihiro Shimizu 890ddd
// altrimenti, 4 byte con val&0x3==0x2;
Shinya Kitaoka 120a6e
// e gli altri (32-2) bit contenenti iol valore di w.
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
inline TUINT32 ulongFromDouble(double x) {
Shinya Kitaoka 120a6e
  assert(x < 1.0);
Shinya Kitaoka 120a6e
  x += 1.0;
Shinya Kitaoka 120a6e
  TUINT32 *l = (TUINT32 *)&x;
Toshihiro Shimizu 890ddd
#if TNZ_LITTLE_ENDIAN
Shinya Kitaoka 120a6e
  TUINT32 hi = l[1], lo = l[0];
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
  TUINT32 hi = l[0], lo = l[1];
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return (hi & 0XFFFFF) << 12 | ((lo & 0xFFE00000) >> 20);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TUINT32 ParsedPliImp::writeIntersectionDataTag(IntersectionDataTag *tag) {
Shinya Kitaoka 120a6e
  TUINT32 offset, tagLength;
Shinya Kitaoka 120a6e
  int maxval = -100000, minval = 100000;
Shinya Kitaoka 120a6e
  //  bool isNew = false;
Shinya Kitaoka 120a6e
  int floatWCount = 0;
Shinya Kitaoka 120a6e
  unsigned int i;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  assert(m_oChan);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (-(int)tag->m_branchCount - 1 < minval)
Shinya Kitaoka 120a6e
    minval = -(int)tag->m_branchCount - 1;
Shinya Kitaoka 120a6e
  if ((int)tag->m_branchCount + 1 > maxval)
Shinya Kitaoka 120a6e
    maxval = (int)tag->m_branchCount + 1;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  for (i = 0; i < tag->m_branchCount; i++) {
Shinya Kitaoka 120a6e
    if (tag->m_branchArray[i].m_w != 0 && tag->m_branchArray[i].m_w != 1)
Shinya Kitaoka 120a6e
      floatWCount++;
Shinya Kitaoka 120a6e
    if (tag->m_branchArray[i].m_strokeIndex < minval)
Shinya Kitaoka 120a6e
      minval = tag->m_branchArray[i].m_strokeIndex;
Shinya Kitaoka 120a6e
    else if (tag->m_branchArray[i].m_strokeIndex > maxval)
Shinya Kitaoka 120a6e
      maxval = tag->m_branchArray[i].m_strokeIndex;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  setDinamicTypeBytesNum(minval, maxval);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  tagLength = 4 + tag->m_branchCount * (3 * m_currDinamicTypeBytesNum + 2) +
Shinya Kitaoka 120a6e
              floatWCount * 8 + (tag->m_branchCount - floatWCount) * 1;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  offset = writeTagHeader((UCHAR)PliTag::INTERSECTION_DATA_GOBJ, tagLength);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  *m_oChan << (TUINT32)tag->m_branchCount;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  for (i = 0; i < tag->m_branchCount; i++) {
Shinya Kitaoka 120a6e
    writeDinamicData((TINT32)tag->m_branchArray[i].m_strokeIndex);
Shinya Kitaoka 120a6e
    writeDinamicData((tag->m_branchArray[i].m_gettingOut)
Shinya Kitaoka 120a6e
                         ? (TINT32)(tag->m_branchArray[i].m_currInter + 1)
Shinya Kitaoka 120a6e
                         : -(TINT32)(tag->m_branchArray[i].m_currInter + 1));
Shinya Kitaoka 120a6e
    writeDinamicData((TUINT32)tag->m_branchArray[i].m_nextBranch);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    assert(tag->m_branchArray[i].m_style >= 0 &&
Shinya Kitaoka 120a6e
           tag->m_branchArray[i].m_style < 65536);
Shinya Kitaoka 120a6e
    *m_oChan << (USHORT)tag->m_branchArray[i].m_style;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    assert(tag->m_branchArray[i].m_w >= 0 && tag->m_branchArray[i].m_w <= 1);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    if (tag->m_branchArray[i].m_w == 0)
Shinya Kitaoka 120a6e
      *m_oChan << ((UCHAR)0x80);
Shinya Kitaoka 120a6e
    else if (tag->m_branchArray[i].m_w == 1)
Shinya Kitaoka 120a6e
      *m_oChan << ((UCHAR)0x81);
Shinya Kitaoka 120a6e
    else {
Shinya Kitaoka 120a6e
      TUINT32 hi, lo;
Shinya Kitaoka 120a6e
      ulongFromDouble1(tag->m_branchArray[i].m_w, hi, lo);
Shinya Kitaoka 120a6e
      assert((hi & 0x80000000) == 0);
Shinya Kitaoka 120a6e
      *m_oChan << (UCHAR)((hi >> 24) & 0xff);
Shinya Kitaoka 120a6e
      *m_oChan << (UCHAR)((hi >> 16) & 0xff);
Shinya Kitaoka 120a6e
      *m_oChan << (UCHAR)((hi >> 8) & 0xff);
Shinya Kitaoka 120a6e
      *m_oChan << (UCHAR)((hi)&0xff);
Shinya Kitaoka 120a6e
      // m_oChan<<((TUINT32)hi);
Shinya Kitaoka 120a6e
      *m_oChan << (TUINT32)(lo);
Shinya Kitaoka 120a6e
      // m_oChan<<((TUINT32)hi);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return offset;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TUINT32 ParsedPliImp::writeColorTag(ColorTag *tag) {
Shinya Kitaoka 120a6e
  assert(m_oChan);
Shinya Kitaoka 120a6e
  TUINT32 tagLength, offset;
Shinya Kitaoka 120a6e
  int maxval = 0, minval = 100000;
Shinya Kitaoka 120a6e
  unsigned int i;
Shinya Kitaoka 120a6e
  for (i = 0; i < tag->m_numColors; i++) {
Shinya Kitaoka 120a6e
    if (tag->m_color[i] < (unsigned int)minval) minval = (int)tag->m_color[i];
Shinya Kitaoka 120a6e
    if (tag->m_color[i] > (unsigned int)maxval) maxval = (int)tag->m_color[i];
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  setDinamicTypeBytesNum(minval, maxval);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  tagLength = tag->m_numColors * m_currDinamicTypeBytesNum + 2;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  offset = writeTagHeader((UCHAR)PliTag::COLOR_NGOBJ, tagLength);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  *m_oChan << (UCHAR)tag->m_style;
Shinya Kitaoka 120a6e
  *m_oChan << (UCHAR)tag->m_attribute;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  for (i = 0; i < tag->m_numColors; i++) writeDinamicData(tag->m_color[i]);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return offset;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TUINT32 ParsedPliImp::writeStyleTag(StyleTag *tag) {
Shinya Kitaoka 120a6e
  assert(m_oChan);
Shinya Kitaoka 120a6e
  TUINT32 tagLength = 0, offset;
Shinya Kitaoka 120a6e
  // int maxval=0, minval = 100000;
Shinya Kitaoka 120a6e
  int i;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  tagLength = 2 + 2;
Shinya Kitaoka 120a6e
  for (i = 0; i < tag->m_numParams; i++)
Shinya Kitaoka 120a6e
    tagLength += 1 + tag->m_param[i].getSize();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  offset = writeTagHeader((UCHAR)PliTag::STYLE_NGOBJ, tagLength);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  *m_oChan << tag->m_id;
Shinya Kitaoka 120a6e
  *m_oChan << tag->m_pageIndex;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  for (i = 0; i < tag->m_numParams; i++) {
Shinya Kitaoka 120a6e
    *m_oChan << (UCHAR)tag->m_param[i].m_type;
Shinya Kitaoka 120a6e
    switch (tag->m_param[i].m_type) {
Shinya Kitaoka 120a6e
    case TStyleParam::SP_BYTE:
Shinya Kitaoka 120a6e
      *m_oChan << (UCHAR)tag->m_param[i].m_numericVal;
Shinya Kitaoka 120a6e
      break;
Shinya Kitaoka 120a6e
    case TStyleParam::SP_USHORT:
Shinya Kitaoka 120a6e
      *m_oChan << (USHORT)tag->m_param[i].m_numericVal;
Shinya Kitaoka 120a6e
      break;
Shinya Kitaoka 120a6e
    case TStyleParam::SP_INT:
Shinya Kitaoka 120a6e
    case TStyleParam::SP_DOUBLE:
Shinya Kitaoka 120a6e
      writeFloatData((double)tag->m_param[i].m_numericVal);
Shinya Kitaoka 120a6e
      break;
Shinya Kitaoka 120a6e
    case TStyleParam::SP_RASTER:
Shinya Kitaoka 120a6e
      *m_oChan << tag->m_param[i].m_r;
Shinya Kitaoka 120a6e
      break;
Shinya Kitaoka 120a6e
    case TStyleParam::SP_STRING:
Shinya Kitaoka 120a6e
      *m_oChan << tag->m_param[i].m_string;
Shinya Kitaoka 120a6e
      break;
Shinya Kitaoka 120a6e
    default:
Shinya Kitaoka 120a6e
      assert(false);
Shinya Kitaoka 120a6e
      break;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return offset;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TUINT32 ParsedPliImp::writeOutlineOptionsTag(StrokeOutlineOptionsTag *tag) {
Shinya Kitaoka 120a6e
  assert(m_oChan);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  const double scale = 1000.0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TINT32 miterLower = scale * tag->m_options.m_miterLower;
Shinya Kitaoka 120a6e
  TINT32 miterUpper = scale * tag->m_options.m_miterUpper;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  setDinamicTypeBytesNum(scale * miterLower, scale * miterUpper);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int tagLength = 2 + 2 * m_currDinamicTypeBytesNum;
Shinya Kitaoka 120a6e
  int offset =
Shinya Kitaoka 120a6e
      (int)writeTagHeader((UCHAR)PliTag::OUTLINE_OPTIONS_GOBJ, tagLength);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  *m_oChan << (UCHAR)tag->m_options.m_capStyle;
Shinya Kitaoka 120a6e
  *m_oChan << (UCHAR)tag->m_options.m_joinStyle;
Shinya Kitaoka 120a6e
  writeDinamicData(miterLower);
Shinya Kitaoka 120a6e
  writeDinamicData(miterUpper);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return offset;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TUINT32 ParsedPliImp::writePrecisionScaleTag(PrecisionScaleTag *tag) {
Shinya Kitaoka 120a6e
  assert(m_oChan);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  setDinamicTypeBytesNum(0, tag->m_precisionScale);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int tagLength = m_currDinamicTypeBytesNum;
Shinya Kitaoka 120a6e
  int offset =
Shinya Kitaoka 120a6e
      (int)writeTagHeader((UCHAR)PliTag::PRECISION_SCALE_GOBJ, tagLength);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  writeDinamicData((TINT32)tag->m_precisionScale);
Shinya Kitaoka 120a6e
  return offset;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TUINT32 ParsedPliImp::writeGeometricTransformationTag(
Shinya Kitaoka 120a6e
    GeometricTransformationTag *tag) {
Shinya Kitaoka 120a6e
  assert(m_oChan);
Shinya Kitaoka 120a6e
  TUINT32 offset, tagLength;
Shinya Kitaoka 120a6e
  int maxval = 0, minval = 100000;
Shinya Kitaoka 120a6e
  TINT32 intVal[6];
Shinya Kitaoka 120a6e
  TUINT32 decVal[6];
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TUINT32 objectOffset = 0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (tag->m_object) {
Shinya Kitaoka 120a6e
    if (!(objectOffset = findOffsetFromTag(tag->m_object)))  // the object was
Shinya Kitaoka 120a6e
                                                             // not already
Shinya Kitaoka 120a6e
                                                             // written before:
Shinya Kitaoka 120a6e
                                                             // write it now
Shinya Kitaoka 120a6e
    {
Shinya Kitaoka 120a6e
      TagElem elem(tag->m_object, 0);
Shinya Kitaoka 120a6e
      writeTag(&elem);
Shinya Kitaoka 120a6e
      objectOffset = elem.m_offset;
Shinya Kitaoka 120a6e
      addTag(elem);
Shinya Kitaoka 120a6e
      elem.m_tag = 0;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (objectOffset < (unsigned int)minval) minval = (int)objectOffset;
Shinya Kitaoka 120a6e
  if (objectOffset > (unsigned int)maxval) maxval = (int)objectOffset;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  getLongValFromFloat(tag->m_affine.a11, intVal[0], decVal[0]);
Shinya Kitaoka 120a6e
  if (intVal[0] < minval) minval               = (int)intVal[0];
Shinya Kitaoka 120a6e
  if (intVal[0] > maxval) maxval               = (int)intVal[0];
Shinya Kitaoka 120a6e
  if (decVal[0] > (unsigned int)maxval) maxval = (int)decVal[0];
Shinya Kitaoka 120a6e
  getLongValFromFloat(tag->m_affine.a12, intVal[1], decVal[1]);
Shinya Kitaoka 120a6e
  if (decVal[1] > (unsigned int)maxval) maxval = (int)decVal[1];
Shinya Kitaoka 120a6e
  if (intVal[1] < minval) minval               = (int)intVal[1];
Shinya Kitaoka 120a6e
  if (intVal[1] > maxval) maxval               = (int)intVal[1];
Shinya Kitaoka 120a6e
  getLongValFromFloat(tag->m_affine.a13, intVal[2], decVal[2]);
Shinya Kitaoka 120a6e
  if (decVal[2] > (unsigned int)maxval) maxval = (int)decVal[2];
Shinya Kitaoka 120a6e
  if (intVal[2] < minval) minval               = (int)intVal[2];
Shinya Kitaoka 120a6e
  if (intVal[2] > maxval) maxval               = (int)intVal[2];
Shinya Kitaoka 120a6e
  getLongValFromFloat(tag->m_affine.a21, intVal[3], decVal[3]);
Shinya Kitaoka 120a6e
  if (decVal[3] > (unsigned int)maxval) maxval = (int)decVal[3];
Shinya Kitaoka 120a6e
  if (intVal[3] < minval) minval               = (int)intVal[3];
Shinya Kitaoka 120a6e
  if (intVal[3] > maxval) maxval               = (int)intVal[3];
Shinya Kitaoka 120a6e
  getLongValFromFloat(tag->m_affine.a22, intVal[4], decVal[4]);
Shinya Kitaoka 120a6e
  if (decVal[4] > (unsigned int)maxval) maxval = (int)decVal[4];
Shinya Kitaoka 120a6e
  if (intVal[4] < minval) minval               = (int)intVal[4];
Shinya Kitaoka 120a6e
  if (intVal[4] > maxval) maxval               = (int)intVal[4];
Shinya Kitaoka 120a6e
  getLongValFromFloat(tag->m_affine.a23, intVal[5], decVal[5]);
Shinya Kitaoka 120a6e
  if (decVal[5] > (unsigned int)maxval) maxval = (int)decVal[5];
Shinya Kitaoka 120a6e
  if (intVal[5] < minval) minval               = (int)intVal[5];
Shinya Kitaoka 120a6e
  if (intVal[5] > maxval) maxval               = (int)intVal[5];
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  setDinamicTypeBytesNum(minval, maxval);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  tagLength = (1 + 6 * 2) * m_currDinamicTypeBytesNum;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  offset =
Shinya Kitaoka 120a6e
      writeTagHeader((UCHAR)PliTag::GEOMETRIC_TRANSFORMATION_GOBJ, tagLength);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  writeDinamicData(intVal[0]);
Shinya Kitaoka 120a6e
  writeDinamicData(decVal[0]);
Shinya Kitaoka 120a6e
  writeDinamicData(intVal[1]);
Shinya Kitaoka 120a6e
  writeDinamicData(decVal[1]);
Shinya Kitaoka 120a6e
  writeDinamicData(intVal[2]);
Shinya Kitaoka 120a6e
  writeDinamicData(decVal[2]);
Shinya Kitaoka 120a6e
  writeDinamicData(intVal[3]);
Shinya Kitaoka 120a6e
  writeDinamicData(decVal[3]);
Shinya Kitaoka 120a6e
  writeDinamicData(intVal[4]);
Shinya Kitaoka 120a6e
  writeDinamicData(decVal[4]);
Shinya Kitaoka 120a6e
  writeDinamicData(intVal[5]);
Shinya Kitaoka 120a6e
  writeDinamicData(decVal[5]);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  writeDinamicData(objectOffset);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return offset;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TUINT32 ParsedPliImp::writeDoublePairTag(DoublePairTag *tag) {
Shinya Kitaoka 120a6e
  TUINT32 offset, tagLength;
Shinya Kitaoka 120a6e
  TINT32 minval = 100000, maxval = 0;
Shinya Kitaoka 120a6e
  TINT32 xIntVal, yIntVal;
Shinya Kitaoka 120a6e
  TUINT32 xDecVal, yDecVal;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  getLongValFromFloat(tag->m_first, xIntVal, xDecVal);
Shinya Kitaoka 120a6e
  getLongValFromFloat(tag->m_second, yIntVal, yDecVal);
Shinya Kitaoka 120a6e
  if (xIntVal < minval) minval      = (int)xIntVal;
Shinya Kitaoka 120a6e
  if (xIntVal > maxval) maxval      = (int)xIntVal;
Shinya Kitaoka 120a6e
  if ((int)xDecVal > maxval) maxval = (int)xDecVal;
Shinya Kitaoka 120a6e
  if (yIntVal < minval) minval      = (int)yIntVal;
Shinya Kitaoka 120a6e
  if (yIntVal > maxval) maxval      = (int)yIntVal;
Shinya Kitaoka 120a6e
  if ((int)yDecVal > maxval) maxval = (int)yDecVal;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  setDinamicTypeBytesNum(minval, maxval);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  tagLength = 4 * m_currDinamicTypeBytesNum;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  offset = writeTagHeader((UCHAR)PliTag::DOUBLEPAIR_OBJ, tagLength);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  writeDinamicData(xIntVal);
Shinya Kitaoka 120a6e
  writeDinamicData(xDecVal);
Shinya Kitaoka 120a6e
  writeDinamicData(yIntVal);
Shinya Kitaoka 120a6e
  writeDinamicData(yDecVal);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return offset;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TUINT32 ParsedPliImp::writeBitmapTag(BitmapTag *tag) {
Shinya Kitaoka 120a6e
  assert(m_oChan);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TUINT32 offset, tagLength;
Shinya Kitaoka 120a6e
  TRaster32P r = tag->m_r;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  UINT bmpSize = r->getLx() * r->getLy() * r->getPixelSize();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  tagLength = 2 + 2 + bmpSize;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  offset = writeTagHeader((UCHAR)PliTag::BITMAP_GOBJ, tagLength);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  *m_oChan << (USHORT)r->getLx();
Shinya Kitaoka 120a6e
  *m_oChan << (USHORT)r->getLy();
Shinya Kitaoka 120a6e
  r->lock();
Shinya Kitaoka 120a6e
  m_oChan->writeBuf(r->getRawData(), bmpSize);
Shinya Kitaoka 120a6e
  r->unlock();
Shinya Kitaoka 120a6e
  return offset;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
/*=====================================================================*/
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
bool ParsedPliImp::writePli(const TFilePath &filename) {
Shinya Kitaoka 120a6e
  MyOfstream os(filename);
Shinya Kitaoka 120a6e
  if (!os || os.fail()) return false;
Shinya Kitaoka 120a6e
  m_oChan = &os;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  *m_oChan << c_magicNt;
Shinya Kitaoka 120a6e
  // m_oChan << c_magicIrix;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  *m_oChan << m_majorVersionNumber;
Shinya Kitaoka 120a6e
  *m_oChan << m_minorVersionNumber;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  *m_oChan << m_creator;
Toshihiro Shimizu 890ddd
MCCCS a0ce32
  *m_oChan << (TUINT32)0;  // fileLength;
Shinya Kitaoka 120a6e
  *m_oChan << m_framesNumber;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  UCHAR s, i, d;
Shinya Kitaoka 120a6e
  double absAutoClose = fabs(m_autocloseTolerance);
Shinya Kitaoka 120a6e
  s                   = tsign(m_autocloseTolerance) + 1;
Shinya Kitaoka 120a6e
  i                   = (UCHAR)((int)absAutoClose);
Shinya Kitaoka 120a6e
  d                   = (UCHAR)((int)((absAutoClose - i) * 100));
Shinya Kitaoka 120a6e
  *m_oChan << s;
Shinya Kitaoka 120a6e
  *m_oChan << i;
Shinya Kitaoka 120a6e
  *m_oChan << d;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  CHECK_FOR_WRITE_ERROR(filename);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_currDinamicTypeBytesNum = 2;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  for (TagElem *elem = m_firstTag; elem; elem = elem->m_next) {
Shinya Kitaoka 120a6e
    writeTag(elem);
Shinya Kitaoka 120a6e
    CHECK_FOR_WRITE_ERROR(filename);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  *m_oChan << (UCHAR)PliTag::END_CNTRL;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_oChan->close();
Shinya Kitaoka 120a6e
  m_oChan = 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
ParsedPli::ParsedPli() { imp = new ParsedPliImp(); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
ParsedPli::ParsedPli(USHORT framesNumber, UCHAR precision, UCHAR maxThickness,
Shinya Kitaoka 120a6e
                     double autocloseTolerance) {
Shinya Kitaoka 120a6e
  imp =
Shinya Kitaoka 120a6e
      new ParsedPliImp(c_majorVersionNumber, c_minorVersionNumber, framesNumber,
Shinya Kitaoka 120a6e
                       precision, maxThickness, autocloseTolerance);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
ParsedPli::~ParsedPli() { delete imp; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool ParsedPli::addTag(PliTag *tag, bool addFront) {
Shinya Kitaoka 120a6e
  return imp->addTag(tag, addFront);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
PliTag *ParsedPli::getFirstTag() {
Shinya Kitaoka 120a6e
  imp->m_currTag = imp->m_firstTag;
Shinya Kitaoka 120a6e
  return imp->m_currTag->m_tag;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
PliTag *ParsedPli::getNextTag() {
Shinya Kitaoka 120a6e
  assert(imp->m_currTag);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  imp->m_currTag = imp->m_currTag->m_next;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return (imp->m_currTag) ? imp->m_currTag->m_tag : NULL;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ParsedPli::setCreator(const QString &creator) {
Shinya Kitaoka 120a6e
  imp->m_creator = creator.toStdString();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QString ParsedPli::getCreator() const {
Shinya Kitaoka 120a6e
  return QString::fromStdString(imp->m_creator);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
ParsedPli::ParsedPli(const TFilePath &filename, bool readInfo) {
Shinya Kitaoka 120a6e
  imp = new ParsedPliImp(filename, readInfo);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ParsedPli::getVersion(UINT &majorVersionNumber,
Shinya Kitaoka 120a6e
                           UINT &minorVersionNumber) const {
Shinya Kitaoka 120a6e
  majorVersionNumber = imp->m_majorVersionNumber;
Shinya Kitaoka 120a6e
  minorVersionNumber = imp->m_minorVersionNumber;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool ParsedPli::writePli(const TFilePath &filename) {
Shinya Kitaoka 120a6e
  return imp->writePli(filename);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*
Toshihiro Shimizu 890ddd
  Necessario per fissare un problema di lettura con le vecchie
Toshihiro Shimizu 890ddd
  versioni di PLI ( < 3 ).
Toshihiro Shimizu 890ddd
 */
Shinya Kitaoka 120a6e
double ParsedPli::getThickRatio() const { return imp->m_thickRatio; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
ParsedPliImp::~ParsedPliImp() {
Shinya Kitaoka 120a6e
  TagElem *tag = m_firstTag;
Shinya Kitaoka 120a6e
  while (tag) {
Shinya Kitaoka 120a6e
    TagElem *auxTag = tag;
Shinya Kitaoka 120a6e
    tag             = tag->m_next;
Shinya Kitaoka 120a6e
    delete auxTag;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ParsedPli::loadInfo(bool readPalette, TPalette *&palette,
Shinya Kitaoka 120a6e
                         TContentHistory *&history) {
Shinya Kitaoka 120a6e
  imp->loadInfo(readPalette, palette, history);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
ImageTag *ParsedPli::loadFrame(const TFrameId &frameId) {
Shinya Kitaoka 120a6e
  return imp->loadFrame(frameId);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ParsedPli::setFrameCount(int frameCount) {
Shinya Kitaoka 120a6e
  imp->setFrameCount(frameCount);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ParsedPliImp::setFrameCount(int frameCount) {
Shinya Kitaoka 120a6e
  m_framesNumber = frameCount;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int ParsedPli::getFrameCount() const { return imp->getFrameCount(); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int ParsedPliImp::getFrameCount() { return m_framesNumber; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
double ParsedPli::getAutocloseTolerance() const {
Shinya Kitaoka 120a6e
  return imp->m_autocloseTolerance;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*=====================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int &ParsedPli::precisionScale() { return imp->m_precisionScale; }