|
Toshihiro Shimizu |
890ddd |
#include <sstream> /* std::ostringstream */</sstream>
|
|
Toshihiro Shimizu |
890ddd |
#include "tfxparam.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "stdfx.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "ino_common.h"
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
toonz6.4sg ではTStandardRasterFx
|
|
Toshihiro Shimizu |
890ddd |
toonz7.0 ではTStandardZeraryFx
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Shinya Kitaoka |
120a6e |
class ino_pn_clouds : public TStandardZeraryFx {
|
|
Shinya Kitaoka |
120a6e |
FX_PLUGIN_DECLARATION(ino_pn_clouds)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TDoubleParamP m_size;
|
|
Shinya Kitaoka |
120a6e |
TDoubleParamP m_z;
|
|
Shinya Kitaoka |
120a6e |
TIntEnumParamP m_octaves;
|
|
Shinya Kitaoka |
120a6e |
TDoubleParamP m_persistance;
|
|
Shinya Kitaoka |
120a6e |
TBoolParamP m_alpha_rendering;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
ino_pn_clouds()
|
|
Shinya Kitaoka |
120a6e |
: m_size(10.0)
|
|
Shinya Kitaoka |
120a6e |
, m_z(0.0)
|
|
Shinya Kitaoka |
120a6e |
, m_octaves(new TIntEnumParam(0, "1"))
|
|
Shinya Kitaoka |
120a6e |
, m_persistance(0.5)
|
|
Shinya Kitaoka |
120a6e |
, m_alpha_rendering(true) {
|
|
Shinya Kitaoka |
120a6e |
this->m_size->setMeasureName("fxLength");
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
bindParam(this, "size", this->m_size);
|
|
Shinya Kitaoka |
120a6e |
bindParam(this, "z", this->m_z);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
bindParam(this, "octaves", this->m_octaves);
|
|
Shinya Kitaoka |
120a6e |
this->m_octaves->addItem(1, "2");
|
|
Shinya Kitaoka |
120a6e |
this->m_octaves->addItem(2, "3");
|
|
Shinya Kitaoka |
120a6e |
this->m_octaves->addItem(3, "4");
|
|
Shinya Kitaoka |
120a6e |
this->m_octaves->addItem(4, "5");
|
|
Shinya Kitaoka |
120a6e |
this->m_octaves->addItem(5, "6");
|
|
Shinya Kitaoka |
120a6e |
this->m_octaves->addItem(6, "7");
|
|
Shinya Kitaoka |
120a6e |
this->m_octaves->addItem(7, "8");
|
|
Shinya Kitaoka |
120a6e |
this->m_octaves->addItem(8, "9");
|
|
Shinya Kitaoka |
120a6e |
this->m_octaves->addItem(9, "10");
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
bindParam(this, "persistance", this->m_persistance);
|
|
Shinya Kitaoka |
120a6e |
bindParam(this, "alpha_rendering", this->m_alpha_rendering);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
this->m_size->setValueRange(0.0, 1000.0);
|
|
Shinya Kitaoka |
120a6e |
this->m_persistance->setValueRange(0.1 * ino::param_range(),
|
|
Shinya Kitaoka |
120a6e |
2.0 * ino::param_range());
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
473e70 |
bool doGetBBox(double frame, TRectD &bBox, const TRenderSettings &info) override {
|
|
Shinya Kitaoka |
120a6e |
bBox = TConsts::infiniteRectD;
|
|
Shinya Kitaoka |
120a6e |
return true;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
473e70 |
bool canHandle(const TRenderSettings &info, double frame) override { return false; }
|
|
Shinya Kitaoka |
473e70 |
void doCompute(TTile &tile, double frame, const TRenderSettings &rend_sets) override;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
FX_PLUGIN_IDENTIFIER(ino_pn_clouds, "inopnCloudsFx");
|
|
Toshihiro Shimizu |
890ddd |
// ------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "igs_perlin_noise.h"
|
|
Shinya Kitaoka |
120a6e |
namespace {
|
|
Shinya Kitaoka |
120a6e |
void fx_(TRasterP in_ras, const double zz, const int octaves,
|
|
Shinya Kitaoka |
120a6e |
const double persistance, const bool alpha_rendering_sw,
|
|
Shinya Kitaoka |
120a6e |
const double a11, const double a12, const double a13, const double a21,
|
|
Shinya Kitaoka |
120a6e |
const double a22, const double a23) {
|
|
Shinya Kitaoka |
120a6e |
igs::perlin_noise::change(
|
|
Shinya Kitaoka |
120a6e |
in_ras->getRawData() // BGRA
|
|
Shinya Kitaoka |
120a6e |
,
|
|
Shinya Kitaoka |
120a6e |
in_ras->getLy(), in_ras->getLx() // =in_ras->getWrap()???
|
|
Shinya Kitaoka |
120a6e |
,
|
|
Shinya Kitaoka |
120a6e |
ino::channels(), ino::bits(in_ras), alpha_rendering_sw, a11, a12, a13,
|
|
Shinya Kitaoka |
120a6e |
a21, a22, a23, zz, 0, octaves, persistance);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
void ino_pn_clouds::doCompute(TTile &tile, double frame,
|
|
Shinya Kitaoka |
120a6e |
const TRenderSettings &rend_sets) {
|
|
Shinya Kitaoka |
120a6e |
/* ------ サポートしていないPixelタイプはエラーを投げる --- */
|
|
Shinya Kitaoka |
120a6e |
if (!((TRaster32P)tile.getRaster()) && !((TRaster64P)tile.getRaster())) {
|
|
Shinya Kitaoka |
120a6e |
throw TRopException("unsupported input pixel type");
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
/* ------ Pixel単位で動作パラメータを得る ----------------- */
|
|
Shinya Kitaoka |
120a6e |
/* 単位変換用スケーリング
|
|
Shinya Kitaoka |
120a6e |
行列値(=外積?=面積?)
|
|
Shinya Kitaoka |
120a6e |
rend_sets.m_affine.det() = a11*a22-a12*a21 // double
|
|
Shinya Kitaoka |
120a6e |
シュリンク値
|
|
Shinya Kitaoka |
120a6e |
rend_sets.m_shrinkX // int
|
|
Shinya Kitaoka |
120a6e |
rend_sets.m_shrinkY // int
|
|
Shinya Kitaoka |
120a6e |
2009-10-09
|
|
Shinya Kitaoka |
120a6e |
必ず1が返るようになり、
|
|
Shinya Kitaoka |
120a6e |
シュリンク値はscale値と中心の移動値として
|
|
Shinya Kitaoka |
120a6e |
m_affineに含まれるようになった、
|
|
Shinya Kitaoka |
120a6e |
いつからか分からない、、、。
|
|
Shinya Kitaoka |
120a6e |
詳細不明。??????????????????
|
|
Shinya Kitaoka |
120a6e |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
/* 動作パラメータを得る */
|
|
Shinya Kitaoka |
120a6e |
const double size = this->m_size->getValue(frame);
|
|
Shinya Kitaoka |
120a6e |
const double zz = this->m_z->getValue(frame);
|
|
Shinya Kitaoka |
120a6e |
const int octaves = this->m_octaves->getValue();
|
|
Shinya Kitaoka |
120a6e |
const double persistance = this->m_persistance->getValue(frame);
|
|
Shinya Kitaoka |
120a6e |
const bool alp_rend_sw = this->m_alpha_rendering->getValue();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TAffine aff = rend_sets.m_affine * TScale(ino::pixel_per_mm());
|
|
Shinya Kitaoka |
120a6e |
const double scale = 1.0 / (size * sqrt(fabs(aff.det())));
|
|
Shinya Kitaoka |
120a6e |
TAffine aff_pn = TScale(scale) * TTranslation(tile.m_pos);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
/* ------ 保存すべき画像メモリを塗りつぶしクリア ---------- */
|
|
Shinya Kitaoka |
120a6e |
tile.getRaster()->clear(); /* 塗りつぶしクリア */
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
/* ------ (app_begin)log記憶 ------------------------------ */
|
|
Shinya Kitaoka |
120a6e |
const bool log_sw = ino::log_enable_sw();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (log_sw) {
|
|
Shinya Kitaoka |
120a6e |
std::ostringstream os;
|
|
Shinya Kitaoka |
120a6e |
os << "params"
|
|
Shinya Kitaoka |
120a6e |
<< " size " << size << " z " << zz << " octaves " << octaves
|
|
Shinya Kitaoka |
120a6e |
<< " persistance " << persistance << " alp_rend_sw " << alp_rend_sw
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
<< " tile w " << tile.getRaster()->getLx() << " h "
|
|
Shinya Kitaoka |
120a6e |
<< tile.getRaster()->getLy() << " pixbits "
|
|
Shinya Kitaoka |
120a6e |
<< ino::pixel_bits(tile.getRaster());
|
|
Shinya Kitaoka |
120a6e |
os << " frame " << frame << " aff_pn scale " << scale << " pos x "
|
|
Shinya Kitaoka |
120a6e |
<< tile.m_pos.x << " y " << tile.m_pos.y;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
/* ------ fx処理 ------------------------------------------ */
|
|
Shinya Kitaoka |
120a6e |
try {
|
|
Shinya Kitaoka |
120a6e |
tile.getRaster()->lock();
|
|
Shinya Kitaoka |
120a6e |
fx_(tile.getRaster(), zz, octaves, persistance, alp_rend_sw, aff_pn.a11,
|
|
Shinya Kitaoka |
120a6e |
aff_pn.a12, aff_pn.a13, aff_pn.a21, aff_pn.a22, aff_pn.a23);
|
|
Shinya Kitaoka |
120a6e |
tile.getRaster()->unlock();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
/* ------ error処理 --------------------------------------- */
|
|
Shinya Kitaoka |
120a6e |
catch (std::bad_alloc &e) {
|
|
Shinya Kitaoka |
120a6e |
tile.getRaster()->unlock();
|
|
Shinya Kitaoka |
120a6e |
if (log_sw) {
|
|
Shinya Kitaoka |
120a6e |
std::string str("std::bad_alloc <");
|
|
Shinya Kitaoka |
120a6e |
str += e.what();
|
|
Shinya Kitaoka |
120a6e |
str += '>';
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
throw;
|
|
Shinya Kitaoka |
120a6e |
} catch (std::exception &e) {
|
|
Shinya Kitaoka |
120a6e |
tile.getRaster()->unlock();
|
|
Shinya Kitaoka |
120a6e |
if (log_sw) {
|
|
Shinya Kitaoka |
120a6e |
std::string str("exception <");
|
|
Shinya Kitaoka |
120a6e |
str += e.what();
|
|
Shinya Kitaoka |
120a6e |
str += '>';
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
throw;
|
|
Shinya Kitaoka |
120a6e |
} catch (...) {
|
|
Shinya Kitaoka |
120a6e |
tile.getRaster()->unlock();
|
|
Shinya Kitaoka |
120a6e |
if (log_sw) {
|
|
Shinya Kitaoka |
120a6e |
std::string str("other exception");
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
throw;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|