|
Toshihiro Shimizu |
890ddd |
#include "tiio_psd.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "trasterimage.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "timageinfo.h"
|
|
Keisuke Ogaki |
e6172d |
#if (defined(x64) || defined(__LP64__))
|
|
Keisuke Ogaki |
5ff9a7 |
#include "toonz/preferences.h"
|
|
Keisuke Ogaki |
8b06ff |
#include <qtcore></qtcore>
|
|
Keisuke Ogaki |
e6172d |
#endif
|
|
Keisuke Ogaki |
8b06ff |
|
|
Toshihiro Shimizu |
890ddd |
// forward declaration
|
|
Shinya Kitaoka |
120a6e |
// class TImageReaderLayerPsd;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// if path = :
|
|
Campbell Barton |
ea4f7e |
// filename.psd to load float image. TLevel frames number is 1
|
|
Shinya Kitaoka |
120a6e |
// filename#layerId.psd to load only one psd layer from layerId. TLevel
|
|
Shinya Kitaoka |
120a6e |
// frames number is 1
|
|
Shinya Kitaoka |
120a6e |
// filename#layerId#frames.psd to load only one psd layer from layerId. TLevel
|
|
Shinya Kitaoka |
120a6e |
// frames number is psd layers number
|
|
Shinya Kitaoka |
120a6e |
// filename#layerId#group.psd to load only one psd layer from layerId. TLevel
|
|
Shinya Kitaoka |
120a6e |
// frames number is psd layers folder number
|
|
Campbell Barton |
ea4f7e |
// where fodler is the folder belongs psd layer.
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TLevelReaderPsd::TLevelReaderPsd(const TFilePath &path)
|
|
Shinya Kitaoka |
120a6e |
: TLevelReader(path), m_path(path), m_layerId(0) {
|
|
Shinya Kitaoka |
120a6e |
m_psdreader = new TPSDReader(m_path);
|
|
Shinya Kitaoka |
120a6e |
TPSDHeaderInfo header = m_psdreader->getPSDHeaderInfo();
|
|
Shinya Kitaoka |
120a6e |
m_lx = header.cols;
|
|
Shinya Kitaoka |
120a6e |
m_ly = header.rows;
|
|
Shinya Kitaoka |
120a6e |
m_layersCount = header.layersCount;
|
|
Shinya Kitaoka |
120a6e |
// set m_info
|
|
Shinya Kitaoka |
120a6e |
m_info = new TImageInfo();
|
|
Shinya Kitaoka |
120a6e |
m_info->m_lx = m_lx;
|
|
Shinya Kitaoka |
120a6e |
m_info->m_ly = m_ly;
|
|
Shinya Kitaoka |
120a6e |
m_info->m_dpix = header.hres;
|
|
Shinya Kitaoka |
120a6e |
m_info->m_dpiy = header.vres;
|
|
Shinya Kitaoka |
120a6e |
m_info->m_bitsPerSample = header.depth;
|
|
Shinya Kitaoka |
120a6e |
m_info->m_samplePerPixel = header.channels;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
QString name = m_path.getName().c_str();
|
|
Shinya Kitaoka |
120a6e |
QStringList list = name.split("#");
|
|
Shinya Kitaoka |
120a6e |
if (list.size() >= 2) {
|
|
Shinya Kitaoka |
120a6e |
// There's a layer id, otherwise the level is loaded in FLAT mode
|
|
Shinya Kitaoka |
120a6e |
const QString &layerStr = list.at(1);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef REF_LAYER_BY_NAME
|
|
Shinya Kitaoka |
120a6e |
#if (defined(x64) || defined(__LP64__))
|
|
Shinya Kitaoka |
120a6e |
if (layerStr != "frames") {
|
|
Shinya Kitaoka |
120a6e |
QTextCodec *layerNameCodec = QTextCodec::codecForName(
|
|
Shinya Kitaoka |
120a6e |
Preferences::instance()->getLayerNameEncoding().c_str());
|
|
Shinya Kitaoka |
120a6e |
TPSDParser psdparser(m_path);
|
|
Shinya Kitaoka |
120a6e |
m_layerId = psdparser.getLevelIdByName(
|
|
Shinya Kitaoka |
120a6e |
layerNameCodec->fromUnicode(layerStr).toStdString());
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
m_layerId = layerStr.toInt();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
#endif
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Shinya Kitaoka |
120a6e |
m_layerId = layerName.toInt();
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TLevelReaderPsd::~TLevelReaderPsd() { delete m_psdreader; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TLevelReaderPsd::load(TRasterImageP &rasP, int shrinkX, int shrinkY,
|
|
Shinya Kitaoka |
120a6e |
TRect region) {
|
|
Shinya Kitaoka |
120a6e |
QMutexLocker sl(&m_mutex);
|
|
Shinya Kitaoka |
120a6e |
TRasterImageP img;
|
|
Shinya Kitaoka |
120a6e |
m_psdreader->setShrink(shrinkX, shrinkY);
|
|
Shinya Kitaoka |
120a6e |
m_psdreader->setRegion(region);
|
|
Shinya Kitaoka |
120a6e |
m_psdreader->load(img, m_layerId); // if layerId==0 load Merged
|
|
Shinya Kitaoka |
120a6e |
rasP = img;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TLevelP TLevelReaderPsd::loadInfo() {
|
|
Shinya Kitaoka |
120a6e |
TPSDParser *psdparser = new TPSDParser(m_path);
|
|
Shinya Kitaoka |
120a6e |
assert(m_layerId >= 0);
|
|
Shinya Kitaoka |
120a6e |
int framesCount = psdparser->getFramesCount(m_layerId);
|
|
Shinya Kitaoka |
120a6e |
TLevelP level;
|
|
Shinya Kitaoka |
120a6e |
level->setName(psdparser->getLevelName(m_layerId));
|
|
Shinya Kitaoka |
120a6e |
m_frameTable.clear();
|
|
Shinya Kitaoka |
120a6e |
for (int i = 0; i < framesCount; i++) {
|
|
Shinya Kitaoka |
120a6e |
TFrameId frame(i + 1);
|
|
Shinya Kitaoka |
120a6e |
m_frameTable.insert(
|
|
Shinya Kitaoka |
120a6e |
std::make_pair(frame, psdparser->getFrameId(m_layerId, i)));
|
|
Shinya Kitaoka |
120a6e |
level->setFrame(frame, TImageP());
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
return level;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TLevelReader *TLevelReaderPsd::create(const TFilePath &f) {
|
|
Shinya Kitaoka |
120a6e |
TLevelReaderPsd *reader = new TLevelReaderPsd(f);
|
|
Shinya Kitaoka |
120a6e |
return reader;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
// TImageReaderLayerPsd
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
d1f6c4 |
class TImageReaderLayerPsd final : public TImageReader {
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
TImageReaderLayerPsd(const TFilePath &, int layerId, TLevelReaderPsd *lr,
|
|
Shinya Kitaoka |
120a6e |
TImageInfo *info);
|
|
Shinya Kitaoka |
120a6e |
~TImageReaderLayerPsd() { m_lr->release(); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
private:
|
|
Shinya Kitaoka |
120a6e |
// not implemented
|
|
Shinya Kitaoka |
120a6e |
TImageReaderLayerPsd(const TImageReaderLayerPsd &);
|
|
Shinya Kitaoka |
120a6e |
TImageReaderLayerPsd &operator=(const TImageReaderLayerPsd &src);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
473e70 |
TImageP load() override;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
473e70 |
const TImageInfo *getImageInfo() const override { return m_info; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
private:
|
|
Shinya Kitaoka |
120a6e |
TPSDReader *m_psdreader;
|
|
Shinya Kitaoka |
120a6e |
TLevelReaderPsd *m_lr;
|
|
Shinya Kitaoka |
120a6e |
TImageInfo *m_info;
|
|
Shinya Kitaoka |
120a6e |
int m_layerId;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TImageReaderLayerPsd::TImageReaderLayerPsd(const TFilePath &path, int layerId,
|
|
Shinya Kitaoka |
120a6e |
TLevelReaderPsd *lr,
|
|
Shinya Kitaoka |
120a6e |
TImageInfo *info)
|
|
Shinya Kitaoka |
120a6e |
: TImageReader(path), m_lr(lr), m_layerId(layerId), m_info(info) {
|
|
Shinya Kitaoka |
120a6e |
m_lr->setLayerId(layerId);
|
|
Shinya Kitaoka |
120a6e |
m_lr->addRef();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TImageP TImageReaderLayerPsd::load() {
|
|
Shinya Kitaoka |
120a6e |
TRasterImageP rasP;
|
|
Shinya Kitaoka |
120a6e |
m_lr->load(rasP, m_shrink, m_shrink, m_region);
|
|
Shinya Kitaoka |
120a6e |
return TRasterImageP(rasP);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TImageReaderP TLevelReaderPsd::getFrameReader(TFrameId fid) {
|
|
Shinya Kitaoka |
120a6e |
int layerId = m_frameTable[fid];
|
|
Shinya Kitaoka |
120a6e |
TImageReaderLayerPsd *ir =
|
|
Shinya Kitaoka |
120a6e |
new TImageReaderLayerPsd(m_path, layerId, this, m_info);
|
|
Shinya Kitaoka |
120a6e |
return TImageReaderP(ir);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
// TImageWriterPsd
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
d1f6c4 |
class TImageWriterPsd final : public TImageWriter {
|
|
Shinya Kitaoka |
120a6e |
int m_layerId;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
TImageWriterPsd(const TFilePath &, int frameIndex, TLevelWriterPsd *);
|
|
Shinya Kitaoka |
120a6e |
~TImageWriterPsd() { m_lwm->release(); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
private:
|
|
Shinya Kitaoka |
120a6e |
// not implemented
|
|
Shinya Kitaoka |
120a6e |
TImageWriterPsd(const TImageWriterPsd &);
|
|
Shinya Kitaoka |
120a6e |
TImageWriterPsd &operator=(const TImageWriterPsd &src);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
// not implemented
|
|
Shinya Kitaoka |
473e70 |
void save(const TImageP &) override;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
private:
|
|
Shinya Kitaoka |
120a6e |
TLevelWriterPsd *m_lwm;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
// TImageWriterPsd
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TImageWriterPsd::TImageWriterPsd(const TFilePath &path, int layerId,
|
|
Shinya Kitaoka |
120a6e |
TLevelWriterPsd *lwm)
|
|
Shinya Kitaoka |
120a6e |
: TImageWriter(path), m_lwm(lwm), m_layerId(layerId) {
|
|
Shinya Kitaoka |
120a6e |
m_lwm->addRef();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
void TImageWriterPsd::save(const TImageP &img) { m_lwm->save(img, m_layerId); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TLevelWriterPsd::save(const TImageP &img, int frameIndex) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
// TLevelWriterPsd
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TLevelWriterPsd::TLevelWriterPsd(const TFilePath &path, TPropertyGroup *winfo)
|
|
Shinya Kitaoka |
120a6e |
: TLevelWriter(path, winfo) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TLevelWriterPsd::~TLevelWriterPsd() {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TImageWriterP TLevelWriterPsd::getFrameWriter(TFrameId fid) {
|
|
Shinya Kitaoka |
120a6e |
int layerId = 0;
|
|
Shinya Kitaoka |
120a6e |
TImageWriterPsd *iwm = new TImageWriterPsd(m_path, layerId, this);
|
|
Shinya Kitaoka |
120a6e |
return TImageWriterP(iwm);
|
|
Toshihiro Shimizu |
890ddd |
}
|