tahoma2d/toonz/sources/image/pli/pli_io.h

491 lines
12 KiB
C
Raw Normal View History

2016-05-17 03:04:11 +12:00
#pragma once
2016-03-19 06:57:51 +13:00
#ifndef _PLI_IO_H
#define _PLI_IO_H
2016-04-15 17:11:23 +12:00
#ifdef _WIN32
2016-03-19 06:57:51 +13:00
#pragma warning(disable : 4661)
#pragma warning(disable : 4018)
#endif
2016-04-15 19:44:40 +12:00
#include <memory>
#include <vector>
2016-03-19 06:57:51 +13:00
#include "tfilepath.h"
#include "tvectorimage.h"
#include "tstroke.h"
#include <QString>
/*=====================================================================
2016-06-15 18:43:10 +12:00
This include file defines classes needed for parsing of the PLI format
2016-03-19 06:57:51 +13:00
designed for use in the paperless consortium.
2016-06-15 18:43:10 +12:00
The classes are designed in reference of the file format as described
2016-03-19 06:57:51 +13:00
in the related paperless document.
====================================================================*/
/*=====================================================================
2016-06-15 18:43:10 +12:00
these headers contains definition for the pixel types,
2016-03-19 06:57:51 +13:00
and for the different curves used (segments, quadratics, cubics)
=====================================================================*/
#include "traster.h"
#include "tcurves.h"
/*=====================================================================
2016-06-15 18:43:10 +12:00
utility macro used to export classes from the dll
2016-03-19 06:57:51 +13:00
(DVAPI: Digital Video Application Progam Interface)
=====================================================================*/
/*=====================================================================
Base class for the generic PLI tag
=====================================================================*/
/*!
2016-06-15 18:43:10 +12:00
This is the base class for the different tags that form the PLI format.
2016-03-19 06:57:51 +13:00
For an explanation of each one of them, refer to the documentation
2016-06-15 18:43:10 +12:00
The different tags can be extracted fronm the class ParsedPli,
2016-03-19 06:57:51 +13:00
using methods getFirstTag and getNextTag.
The tag type is stored in m_type member.
*/
2016-06-15 18:43:10 +12:00
class PliTag {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
enum Type {
NONE = -1,
END_CNTRL = 0,
SET_DATA_8_CNTRL,
SET_DATA_16_CNTRL,
SET_DATA_32_CNTRL,
TEXT,
PALETTE,
PALETTE_WITH_ALPHA,
DUMMY1,
DUMMY2,
DUMMY3,
THICK_QUADRATIC_CHAIN_GOBJ,
DUMMY4,
DUMMY5,
BITMAP_GOBJ,
GROUP_GOBJ,
TRANSFORMATION_GOBJ,
IMAGE_GOBJ,
COLOR_NGOBJ,
GEOMETRIC_TRANSFORMATION_GOBJ,
DOUBLEPAIR_OBJ,
STYLE_NGOBJ,
INTERSECTION_DATA_GOBJ,
IMAGE_BEGIN_GOBJ,
THICK_QUADRATIC_LOOP_GOBJ,
OUTLINE_OPTIONS_GOBJ,
PRECISION_SCALE_GOBJ,
// ...
HOW_MANY_TAG_TYPES
};
Type m_type;
PliTag();
PliTag(const Type type);
virtual ~PliTag(){};
// PliTag(const PliTag &tag);
2016-03-19 06:57:51 +13:00
};
//=====================================================================
2016-06-15 18:43:10 +12:00
class TStyleParam {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
enum Type {
SP_NONE = 0,
SP_BYTE,
SP_INT,
SP_DOUBLE,
SP_USHORT,
SP_RASTER,
SP_STRING,
SP_HOWMANY
};
Type m_type;
double m_numericVal;
TRaster32P m_r;
std::string m_string;
TStyleParam() : m_type(SP_NONE), m_numericVal(0), m_r(), m_string() {}
TStyleParam(const TStyleParam &styleParam)
: m_type(styleParam.m_type)
, m_numericVal(styleParam.m_numericVal)
, m_r(styleParam.m_r)
, m_string(styleParam.m_string) {}
TStyleParam(double x)
: m_type(SP_DOUBLE), m_numericVal(x), m_r(), m_string() {}
TStyleParam(int x) : m_type(SP_INT), m_numericVal(x), m_r(), m_string() {}
TStyleParam(BYTE x) : m_type(SP_BYTE), m_numericVal(x), m_r(), m_string() {}
TStyleParam(USHORT x)
: m_type(SP_USHORT), m_numericVal(x), m_r(), m_string() {}
TStyleParam(const TRaster32P &x)
: m_type(SP_RASTER), m_numericVal(0), m_r(x), m_string() {}
TStyleParam(const std::string &x)
: m_type(SP_STRING), m_numericVal(0), m_r(), m_string(x) {}
UINT getSize();
2016-03-19 06:57:51 +13:00
};
/*=====================================================================
Subclasses useful to a ierarchical structure of the tags
=====================================================================*/
2016-06-15 18:43:10 +12:00
class PliObjectTag : public PliTag {
2016-03-19 06:57:51 +13:00
protected:
2016-06-15 18:43:10 +12:00
PliObjectTag();
PliObjectTag(const Type type);
2016-03-19 06:57:51 +13:00
};
/*=====================================================================*/
2016-06-15 18:43:10 +12:00
class PliGeometricTag : public PliObjectTag {
2016-03-19 06:57:51 +13:00
protected:
2016-06-15 18:43:10 +12:00
PliGeometricTag();
PliGeometricTag(const Type type);
2016-03-19 06:57:51 +13:00
};
/*=====================================================================
2016-06-15 18:43:10 +12:00
real tags; their structures resembles the structure in the PLI file and
2016-03-19 06:57:51 +13:00
the description in the PLI specific document
=====================================================================*/
2016-06-15 18:43:10 +12:00
class TextTag : public PliObjectTag {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
std::string m_text;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TextTag();
TextTag(const TextTag &textTag);
TextTag(const std::string &text);
2016-03-19 06:57:51 +13:00
};
//=====================================================================
/*!
*/
2016-06-15 18:43:10 +12:00
class PaletteTag : public PliTag {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TUINT32 m_numColors;
TPixelRGBM32 *m_color;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
PaletteTag();
PaletteTag(TUINT32 numColors, TPixelRGBM32 *m_color);
PaletteTag(const PaletteTag &paletteTag);
~PaletteTag();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool setColor(const TUINT32 index, const TPixelRGBM32 &color);
2016-03-19 06:57:51 +13:00
};
//=====================================================================
/*!
*/
2016-06-15 18:43:10 +12:00
class PaletteWithAlphaTag : public PliTag {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TUINT32 m_numColors;
TPixelRGBM32 *m_color;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
PaletteWithAlphaTag();
PaletteWithAlphaTag(TUINT32 numColors);
PaletteWithAlphaTag(TUINT32 numColors, TPixelRGBM32 *m_color);
PaletteWithAlphaTag(PaletteWithAlphaTag &paletteTag);
~PaletteWithAlphaTag();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool setColor(const TUINT32 index, const TPixelRGBM32 &color);
2016-03-19 06:57:51 +13:00
};
//=====================================================================
/*!
2016-06-15 18:43:10 +12:00
All the geometric tags that contains curve informations are
2016-03-19 06:57:51 +13:00
instantiations of this template class
*/
2016-06-15 18:43:10 +12:00
class ThickQuadraticChainTag : public PliGeometricTag {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TUINT32 m_numCurves;
std::unique_ptr<TThickQuadratic[]> m_curve;
bool m_isLoop;
double m_maxThickness;
TStroke::OutlineOptions m_outlineOptions;
ThickQuadraticChainTag()
: PliGeometricTag(THICK_QUADRATIC_CHAIN_GOBJ)
, m_numCurves(0)
, m_maxThickness(1) {}
ThickQuadraticChainTag(TUINT32 numCurves, const TThickQuadratic *curve,
double maxThickness)
: PliGeometricTag(THICK_QUADRATIC_CHAIN_GOBJ)
, m_numCurves(numCurves)
, m_maxThickness(maxThickness <= 0 ? 1 : maxThickness) {
if (m_numCurves > 0) {
m_curve.reset(new TThickQuadratic[m_numCurves]);
for (UINT i = 0; i < m_numCurves; i++) {
m_curve[i] = curve[i];
}
}
}
ThickQuadraticChainTag(const ThickQuadraticChainTag &chainTag)
: PliGeometricTag(THICK_QUADRATIC_CHAIN_GOBJ)
, m_numCurves(chainTag.m_numCurves)
, m_maxThickness(chainTag.m_maxThickness) {
if (m_numCurves > 0) {
m_curve.reset(new TThickQuadratic[m_numCurves]);
for (UINT i = 0; i < m_numCurves; i++) {
m_curve[i] = chainTag.m_curve[i];
}
}
}
2016-03-19 06:57:51 +13:00
private:
2016-06-15 18:43:10 +12:00
// not implemented
const ThickQuadraticChainTag &operator =(
const ThickQuadraticChainTag &chainTag) = delete;
2016-03-19 06:57:51 +13:00
};
//=====================================================================
//=====================================================================
/*!
Not yet implemented
*/
2016-06-15 18:43:10 +12:00
class BitmapTag : public PliGeometricTag {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
enum compressionType { NONE = 0, RLE, HOW_MANY_COMPRESSION };
TRaster32P m_r;
BitmapTag();
BitmapTag(const TRaster32P &r);
BitmapTag(const BitmapTag &bitmap);
~BitmapTag();
2016-03-19 06:57:51 +13:00
};
//=====================================================================
/*!
Not yet implemented
*/
2016-06-15 18:43:10 +12:00
class ColorTag : public PliObjectTag {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
enum styleType {
STYLE_NONE = 0,
SOLID,
LINEAR_GRADIENT,
RADIAL_GRADIENT,
STYLE_HOW_MANY
};
enum attributeType {
ATTRIBUTE_NONE = 0,
EVENODD_LOOP_FILL,
DIRECTION_LOOP_FILL,
STROKE_COLOR,
LEFT_STROKE_COLOR,
RIGHT_STROKE_COLOR,
ATTRIBUTE_HOW_MANY
};
styleType m_style;
attributeType m_attribute;
TUINT32 m_numColors;
std::unique_ptr<TUINT32[]> m_color;
ColorTag();
ColorTag(styleType style, attributeType attribute, TUINT32 numColors,
std::unique_ptr<TUINT32[]> color);
ColorTag(const ColorTag &colorTag);
~ColorTag();
2016-03-19 06:57:51 +13:00
};
//=====================================================================
2016-06-15 18:43:10 +12:00
class StyleTag : public PliObjectTag {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
USHORT m_id;
USHORT m_pageIndex;
int m_numParams;
std::unique_ptr<TStyleParam[]> m_param;
StyleTag();
StyleTag(int id, USHORT pagePaletteindex, int m_numParams,
TStyleParam *m_params);
StyleTag(const StyleTag &trasformationTag);
~StyleTag();
2016-03-19 06:57:51 +13:00
};
//=====================================================================
2016-06-15 18:43:10 +12:00
class GeometricTransformationTag : public PliGeometricTag {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TAffine m_affine;
PliGeometricTag *m_object;
GeometricTransformationTag();
GeometricTransformationTag(const TAffine &affine, PliGeometricTag *m_object);
GeometricTransformationTag(
const GeometricTransformationTag &trasformationTag);
~GeometricTransformationTag();
2016-03-19 06:57:51 +13:00
};
//=====================================================================
2016-06-15 18:43:10 +12:00
class GroupTag : public PliObjectTag {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
enum {
NONE = 0,
STROKE,
SKETCH_STROKE,
LOOP,
FILL_SEED, //(1 ColorTag + 1 pointTag)
PALETTE,
TYPE_HOW_MANY
};
UCHAR m_type;
TUINT32 m_numObjects;
std::unique_ptr<PliObjectTag *[]> m_object;
GroupTag();
GroupTag(UCHAR type, TUINT32 numObjects, PliObjectTag **object);
GroupTag(UCHAR type, TUINT32 numObjects,
std::unique_ptr<PliObjectTag *[]> object);
GroupTag(const GroupTag &groupTag);
~GroupTag();
2016-03-19 06:57:51 +13:00
};
//=====================================================================
2016-06-15 18:43:10 +12:00
class ImageTag : public PliObjectTag {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TFrameId m_numFrame;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TUINT32 m_numObjects;
std::unique_ptr<PliObjectTag *[]> m_object;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// ImageTag();
ImageTag(const TFrameId &numFrame, TUINT32 numObjects, PliObjectTag **object);
ImageTag(const TFrameId &frameId, TUINT32 numObjects,
std::unique_ptr<PliObjectTag *[]> object);
ImageTag(const ImageTag &imageTag);
~ImageTag();
2016-03-19 06:57:51 +13:00
};
//=====================================================================
2016-06-15 18:43:10 +12:00
class DoublePairTag : public PliObjectTag {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
double m_first, m_second;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
DoublePairTag();
DoublePairTag(double x, double y);
DoublePairTag(const DoublePairTag &pointTag);
~DoublePairTag();
2016-03-19 06:57:51 +13:00
};
//=====================================================================
2016-06-15 18:43:10 +12:00
class IntersectionDataTag : public PliObjectTag {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
UINT m_branchCount;
std::unique_ptr<TVectorImage::IntersectionBranch[]> m_branchArray;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
IntersectionDataTag();
IntersectionDataTag(
UINT branchCount,
std::unique_ptr<TVectorImage::IntersectionBranch[]> branchArray);
IntersectionDataTag(const IntersectionDataTag &tag);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
~IntersectionDataTag();
2016-03-19 06:57:51 +13:00
};
//=====================================================================
2016-06-15 18:43:10 +12:00
class StrokeOutlineOptionsTag : public PliObjectTag {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TStroke::OutlineOptions m_options;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
StrokeOutlineOptionsTag();
StrokeOutlineOptionsTag(const TStroke::OutlineOptions &options);
2016-03-19 06:57:51 +13:00
};
//=====================================================================
2016-06-15 18:43:10 +12:00
class PrecisionScaleTag : public PliObjectTag {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
int m_precisionScale;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
PrecisionScaleTag();
PrecisionScaleTag(int precisionScale);
2016-03-19 06:57:51 +13:00
};
//=====================================================================
/*!
2016-06-15 18:43:10 +12:00
The class which will store the parsed info in reading.
2016-03-19 06:57:51 +13:00
(reading is realized by means of the constructor)
and that must be filled up in writing(using writePli).
2016-06-15 18:43:10 +12:00
Notice that implementation is opaque at this level (by means class
ParsedPliImp).
2016-03-19 06:57:51 +13:00
*/
class ParsedPliImp;
class TFilePath;
class TContentHistory;
2016-06-15 18:43:10 +12:00
class ParsedPli {
2016-03-19 06:57:51 +13:00
protected:
2016-06-15 18:43:10 +12:00
ParsedPliImp *imp;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
void setFrameCount(int);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
ParsedPli();
ParsedPli(const TFilePath &filename, bool readInfo = false);
ParsedPli(USHORT framesNumber, UCHAR precision, UCHAR maxThickness,
double autocloseTolerance);
~ParsedPli();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
QString getCreator() const;
void setCreator(const QString &creator);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void getVersion(UINT &majorVersionNumber, UINT &minorVersionNumber) const;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool addTag(PliTag *tag, bool addFront = false);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void loadInfo(bool readPalette, TPalette *&palette,
TContentHistory *&history);
ImageTag *loadFrame(const TFrameId &frameId);
const TFrameId &getFrameNumber(int index);
int getFrameCount() const;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
double getThickRatio() const;
double getMaxThickness() const;
void setMaxThickness(double maxThickness);
double getAutocloseTolerance() const;
int &precisionScale();
// aggiuti questi 2 membri per salvare la paletta globale
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// vector<bool> m_idWrittenColorsArray;
std::vector<PliObjectTag *> m_palette_tags;
// these two functions are used to browse the tag list,
// code example: for (PliTag *tag = getFirstTag(); tag; tag = getNextTag())
// {}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
PliTag *getFirstTag();
PliTag *getNextTag();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool writePli(const TFilePath &filename);
void setCreator(std::string creator);
2016-03-19 06:57:51 +13:00
};
#endif