tahoma2d/toonz/sources/stdfx/ino_pn_clouds.cpp

165 lines
5.7 KiB
C++
Raw Normal View History

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