|
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"
|
|
shun-iwasawa |
8cac36 |
#include "globalcontrollablefx.h"
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------
|
|
shun-iwasawa |
8cac36 |
class ino_hsv_add final : public GlobalControllableFx {
|
|
Shinya Kitaoka |
120a6e |
FX_PLUGIN_DECLARATION(ino_hsv_add)
|
|
Shinya Kitaoka |
120a6e |
TRasterFxPort m_input;
|
|
Shinya Kitaoka |
120a6e |
TRasterFxPort m_noise;
|
|
Shinya Kitaoka |
120a6e |
TRasterFxPort m_refer;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TIntEnumParamP m_from_rgba;
|
|
Shinya Kitaoka |
120a6e |
TDoubleParamP m_offset;
|
|
Shinya Kitaoka |
120a6e |
TDoubleParamP m_hue;
|
|
Shinya Kitaoka |
120a6e |
TDoubleParamP m_sat;
|
|
Shinya Kitaoka |
120a6e |
TDoubleParamP m_val;
|
|
Shinya Kitaoka |
120a6e |
TDoubleParamP m_alp;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TBoolParamP m_anti_alias;
|
|
Shinya Kitaoka |
120a6e |
TIntEnumParamP m_ref_mode;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
ino_hsv_add()
|
|
Shinya Kitaoka |
120a6e |
: m_from_rgba(new TIntEnumParam(0, "Red"))
|
|
Shinya Kitaoka |
120a6e |
, m_offset(0.5 * ino::param_range())
|
|
Shinya Kitaoka |
120a6e |
, m_hue(0.0 * ino::param_range())
|
|
Shinya Kitaoka |
120a6e |
, m_sat(0.0 * ino::param_range())
|
|
Shinya Kitaoka |
120a6e |
, m_val(0.25 * ino::param_range())
|
|
Shinya Kitaoka |
120a6e |
, m_alp(0.0 * ino::param_range())
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
, m_anti_alias(true)
|
|
Shinya Kitaoka |
120a6e |
, m_ref_mode(new TIntEnumParam(0, "Red")) {
|
|
Shinya Kitaoka |
120a6e |
addInputPort("Source", this->m_input);
|
|
Shinya Kitaoka |
120a6e |
addInputPort("Noise", this->m_noise);
|
|
Shinya Kitaoka |
120a6e |
addInputPort("Reference", this->m_refer);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
bindParam(this, "from_rgba", this->m_from_rgba);
|
|
Shinya Kitaoka |
120a6e |
bindParam(this, "offset", this->m_offset);
|
|
Shinya Kitaoka |
120a6e |
bindParam(this, "hue", this->m_hue);
|
|
Shinya Kitaoka |
120a6e |
bindParam(this, "saturation", this->m_sat);
|
|
Shinya Kitaoka |
120a6e |
bindParam(this, "value", this->m_val);
|
|
Shinya Kitaoka |
120a6e |
bindParam(this, "alpha", this->m_alp);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
bindParam(this, "anti_alias", this->m_anti_alias);
|
|
Shinya Kitaoka |
120a6e |
bindParam(this, "reference", this->m_ref_mode);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
this->m_from_rgba->addItem(1, "Green");
|
|
Shinya Kitaoka |
120a6e |
this->m_from_rgba->addItem(2, "Blue");
|
|
Shinya Kitaoka |
120a6e |
this->m_from_rgba->addItem(3, "Alpha");
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
this->m_offset->setValueRange(-1.0 * ino::param_range(),
|
|
Shinya Kitaoka |
120a6e |
1.0 * ino::param_range());
|
|
Shinya Kitaoka |
120a6e |
this->m_hue->setValueRange(-1.0 * ino::param_range(),
|
|
Shinya Kitaoka |
120a6e |
1.0 * ino::param_range());
|
|
Shinya Kitaoka |
120a6e |
this->m_sat->setValueRange(-1.0 * ino::param_range(),
|
|
Shinya Kitaoka |
120a6e |
1.0 * ino::param_range());
|
|
Shinya Kitaoka |
120a6e |
this->m_val->setValueRange(-1.0 * ino::param_range(),
|
|
Shinya Kitaoka |
120a6e |
1.0 * ino::param_range());
|
|
Shinya Kitaoka |
120a6e |
this->m_alp->setValueRange(-1.0 * ino::param_range(),
|
|
Shinya Kitaoka |
120a6e |
1.0 * ino::param_range());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
this->m_ref_mode->addItem(1, "Green");
|
|
Shinya Kitaoka |
120a6e |
this->m_ref_mode->addItem(2, "Blue");
|
|
Shinya Kitaoka |
120a6e |
this->m_ref_mode->addItem(3, "Alpha");
|
|
Shinya Kitaoka |
120a6e |
this->m_ref_mode->addItem(4, "Luminance");
|
|
Shinya Kitaoka |
120a6e |
this->m_ref_mode->addItem(-1, "Nothing");
|
|
shun-iwasawa |
481b59 |
|
|
shun-iwasawa |
481b59 |
enableComputeInFloat(true);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
38fd86 |
bool doGetBBox(double frame, TRectD &bBox,
|
|
Shinya Kitaoka |
38fd86 |
const TRenderSettings &info) override {
|
|
Shinya Kitaoka |
120a6e |
if (this->m_input.isConnected()) {
|
|
Shinya Kitaoka |
120a6e |
return this->m_input->doGetBBox(frame, bBox, info);
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
bBox = TRectD();
|
|
Shinya Kitaoka |
120a6e |
return false;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
473e70 |
bool canHandle(const TRenderSettings &rend_sets, double frame) override {
|
|
Shinya Kitaoka |
120a6e |
return true;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
38fd86 |
void doCompute(TTile &tile, double frame,
|
|
Shinya Kitaoka |
38fd86 |
const TRenderSettings &rend_sets) override;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
FX_PLUGIN_IDENTIFIER(ino_hsv_add, "inohsvAddFx");
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
#include "igs_hsv_add.h"
|
|
Shinya Kitaoka |
120a6e |
namespace {
|
|
Shinya Kitaoka |
120a6e |
void fx_(TRasterP in_ras, const TRasterP noise_ras, const TRasterP refer_ras,
|
|
masafumi-inoue |
26f824 |
const int refer_mode
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
,
|
|
Shinya Kitaoka |
120a6e |
const int xoffset, const int yoffset, const int from_rgba,
|
|
Shinya Kitaoka |
120a6e |
const double offset, const double hue_scale, const double sat_scale,
|
|
Shinya Kitaoka |
120a6e |
const double val_scale, const double alp_scale,
|
|
Shinya Kitaoka |
120a6e |
const bool anti_alias_sw) {
|
|
Shinya Kitaoka |
120a6e |
/***std::vector<unsigned char=""> in_vec;</unsigned>
|
|
Shinya Kitaoka |
120a6e |
ino::ras_to_vec( in_ras, ino::channels(), in_vec );
|
|
Shinya Kitaoka |
120a6e |
std::vector<unsigned char=""> refer_vec;</unsigned>
|
|
Shinya Kitaoka |
120a6e |
ino::ras_to_vec( noise_ras, ino::channels(), refer_vec );***/
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
481b59 |
TRasterGR8P ref_gr8;
|
|
shun-iwasawa |
481b59 |
if ((refer_ras != nullptr) && (0 <= refer_mode)) {
|
|
shun-iwasawa |
481b59 |
ref_gr8 = TRasterGR8P(in_ras->getLy(), in_ras->getLx() * sizeof(float));
|
|
shun-iwasawa |
481b59 |
ref_gr8->lock();
|
|
shun-iwasawa |
481b59 |
ino::ras_to_ref_float_arr(refer_ras,
|
|
shun-iwasawa |
481b59 |
reinterpret_cast<float *="">(ref_gr8->getRawData()),</float>
|
|
shun-iwasawa |
481b59 |
refer_mode);
|
|
shun-iwasawa |
481b59 |
}
|
|
shun-iwasawa |
481b59 |
|
|
Shinya Kitaoka |
120a6e |
TRasterGR8P in_gr8(in_ras->getLy(),
|
|
shun-iwasawa |
481b59 |
in_ras->getLx() * ino::channels() * sizeof(float));
|
|
Shinya Kitaoka |
120a6e |
in_gr8->lock();
|
|
shun-iwasawa |
481b59 |
ino::ras_to_float_arr(in_ras, ino::channels(),
|
|
shun-iwasawa |
481b59 |
reinterpret_cast<float *="">(in_gr8->getRawData()));</float>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TRasterGR8P noise_gr8(noise_ras->getLy(),
|
|
shun-iwasawa |
481b59 |
noise_ras->getLx() * ino::channels() * sizeof(float));
|
|
Shinya Kitaoka |
120a6e |
noise_gr8->lock();
|
|
shun-iwasawa |
481b59 |
ino::ras_to_float_arr(noise_ras, ino::channels(),
|
|
shun-iwasawa |
481b59 |
reinterpret_cast<float *="">(noise_gr8->getRawData()));</float>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
igs::hsv_add::change(
|
|
shun-iwasawa |
481b59 |
reinterpret_cast<float *="">(in_gr8->getRawData()), in_ras->getLy(),</float>
|
|
shun-iwasawa |
481b59 |
in_ras->getLx() // Not use in_ras->getWrap()
|
|
Shinya Kitaoka |
120a6e |
,
|
|
shun-iwasawa |
481b59 |
ino::channels(), reinterpret_cast<float *="">(noise_gr8->getRawData()),</float>
|
|
shun-iwasawa |
481b59 |
(ref_gr8) ? reinterpret_cast<float *="">(ref_gr8->getRawData()) : nullptr,</float>
|
|
Shinya Kitaoka |
120a6e |
xoffset, yoffset, from_rgba, offset, hue_scale, sat_scale, val_scale,
|
|
shun-iwasawa |
481b59 |
alp_scale, anti_alias_sw);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
/***ino::vec_to_ras( refer_vec, 0, 0 );
|
|
Shinya Kitaoka |
120a6e |
ino::vec_to_ras( in_vec, ino::channels(), in_ras, 0 );***/
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
481b59 |
ino::float_arr_to_ras(in_gr8->getRawData(), ino::channels(), in_ras, 0);
|
|
Shinya Kitaoka |
120a6e |
noise_gr8->unlock();
|
|
Shinya Kitaoka |
120a6e |
in_gr8->unlock();
|
|
shun-iwasawa |
481b59 |
|
|
shun-iwasawa |
481b59 |
if (ref_gr8) ref_gr8->unlock();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
shun-iwasawa |
8cac36 |
} // namespace
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
void ino_hsv_add::doCompute(TTile &tile, double frame,
|
|
Shinya Kitaoka |
120a6e |
const TRenderSettings &rend_sets) {
|
|
Shinya Kitaoka |
120a6e |
/* ------ 両方とも接続していなければ処理しない ------------ */
|
|
Shinya Kitaoka |
120a6e |
const bool in_cn_is = this->m_input.isConnected();
|
|
Shinya Kitaoka |
120a6e |
const bool noise_cn_is = this->m_noise.isConnected();
|
|
Shinya Kitaoka |
120a6e |
if (!in_cn_is || !noise_cn_is) {
|
|
Shinya Kitaoka |
120a6e |
tile.getRaster()->clear(); /* 塗りつぶしクリア */
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
/* ------ サポートしていないPixelタイプはエラーを投げる --- */
|
|
shun-iwasawa |
481b59 |
if (!((TRaster32P)tile.getRaster()) && !((TRaster64P)tile.getRaster()) &&
|
|
shun-iwasawa |
481b59 |
!((TRasterFP)tile.getRaster())) {
|
|
Shinya Kitaoka |
120a6e |
throw TRopException("unsupported input pixel type");
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
/* ------ 動作パラメータを得る ---------------------------- */
|
|
Shinya Kitaoka |
120a6e |
const int xoffset = 0.0;
|
|
Shinya Kitaoka |
120a6e |
const int yoffset = 0.0;
|
|
Shinya Kitaoka |
120a6e |
const int from_rgba = this->m_from_rgba->getValue();
|
|
Shinya Kitaoka |
120a6e |
const double offset = this->m_offset->getValue(frame) / ino::param_range();
|
|
Shinya Kitaoka |
120a6e |
const double hue_scale = this->m_hue->getValue(frame) / ino::param_range();
|
|
Shinya Kitaoka |
120a6e |
const double sat_scale = this->m_sat->getValue(frame) / ino::param_range();
|
|
Shinya Kitaoka |
120a6e |
const double val_scale = this->m_val->getValue(frame) / ino::param_range();
|
|
Shinya Kitaoka |
120a6e |
const double alp_scale = this->m_alp->getValue(frame) / ino::param_range();
|
|
Shinya Kitaoka |
120a6e |
const bool anti_alias_sw = this->m_anti_alias->getValue();
|
|
masafumi-inoue |
26f824 |
const int refer_mode = this->m_ref_mode->getValue();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
/* ------ 画像生成 ---------------------------------------- */
|
|
Shinya Kitaoka |
120a6e |
this->m_input->compute(tile, frame, rend_sets);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
/* ------ noise画像生成 ------------------------------------ */
|
|
Shinya Kitaoka |
120a6e |
TTile noise_tile;
|
|
Shinya Kitaoka |
120a6e |
this->m_noise->allocateAndCompute(noise_tile, tile.m_pos,
|
|
Shinya Kitaoka |
120a6e |
tile.getRaster()->getSize(),
|
|
Shinya Kitaoka |
120a6e |
tile.getRaster(), frame, rend_sets);
|
|
Shinya Kitaoka |
120a6e |
/*------ 参照画像生成 --------------------------------------*/
|
|
masafumi-inoue |
26f824 |
TTile refer_tile;
|
|
masafumi-inoue |
26f824 |
bool refer_sw = false;
|
|
Shinya Kitaoka |
120a6e |
if (this->m_refer.isConnected()) {
|
|
masafumi-inoue |
26f824 |
refer_sw = true;
|
|
Shinya Kitaoka |
120a6e |
this->m_refer->allocateAndCompute(
|
|
masafumi-inoue |
26f824 |
refer_tile, tile.m_pos,
|
|
Shinya Kitaoka |
120a6e |
TDimensionI(/* Pixel単位 */
|
|
Shinya Kitaoka |
120a6e |
tile.getRaster()->getLx(), tile.getRaster()->getLy()),
|
|
Shinya Kitaoka |
120a6e |
tile.getRaster(), frame, rend_sets);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
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 |
<< " xo " << xoffset << " yo " << yoffset << " rgba " << from_rgba
|
|
Shinya Kitaoka |
120a6e |
<< " offs " << offset << " h " << hue_scale << " s " << sat_scale
|
|
Shinya Kitaoka |
120a6e |
<< " v " << val_scale << " a " << alp_scale << " anti_alias "
|
|
masafumi-inoue |
26f824 |
<< anti_alias_sw << " reference " << refer_mode << " tile w "
|
|
Shinya Kitaoka |
120a6e |
<< tile.getRaster()->getLx() << " h " << tile.getRaster()->getLy()
|
|
Shinya Kitaoka |
120a6e |
<< " pixbits " << ino::pixel_bits(tile.getRaster())
|
|
Shinya Kitaoka |
120a6e |
<< " noise_tile w " << noise_tile.getRaster()->getLx() << " h "
|
|
Shinya Kitaoka |
120a6e |
<< noise_tile.getRaster()->getLy() << " frame " << frame;
|
|
masafumi-inoue |
26f824 |
if (refer_sw) {
|
|
masafumi-inoue |
26f824 |
os << " refer_tile.m_pos " << refer_tile.m_pos << " refer_tile_getLx "
|
|
masafumi-inoue |
26f824 |
<< refer_tile.getRaster()->getLx() << " y "
|
|
masafumi-inoue |
26f824 |
<< refer_tile.getRaster()->getLy();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
/* ------ fx処理 ------------------------------------------ */
|
|
Shinya Kitaoka |
120a6e |
try {
|
|
Shinya Kitaoka |
120a6e |
tile.getRaster()->lock();
|
|
Shinya Kitaoka |
120a6e |
noise_tile.getRaster()->lock();
|
|
masafumi-inoue |
26f824 |
if (refer_tile.getRaster() != nullptr) {
|
|
masafumi-inoue |
26f824 |
refer_tile.getRaster()->lock();
|
|
masafumi-inoue |
26f824 |
}
|
|
masafumi-inoue |
26f824 |
fx_(tile.getRaster(), noise_tile.getRaster(), refer_tile.getRaster(),
|
|
masafumi-inoue |
26f824 |
refer_mode
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
,
|
|
Shinya Kitaoka |
120a6e |
xoffset, yoffset, from_rgba, offset, hue_scale, sat_scale, val_scale,
|
|
Shinya Kitaoka |
120a6e |
alp_scale, anti_alias_sw // --> add_blend_sw, default is true
|
|
shun-iwasawa |
8cac36 |
);
|
|
masafumi-inoue |
26f824 |
if (refer_tile.getRaster() != nullptr) {
|
|
masafumi-inoue |
26f824 |
refer_tile.getRaster()->unlock();
|
|
masafumi-inoue |
26f824 |
}
|
|
Shinya Kitaoka |
120a6e |
noise_tile.getRaster()->unlock();
|
|
Shinya Kitaoka |
120a6e |
tile.getRaster()->unlock();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
/* ------ error処理 --------------------------------------- */
|
|
Shinya Kitaoka |
120a6e |
catch (std::bad_alloc &e) {
|
|
masafumi-inoue |
26f824 |
if (refer_tile.getRaster() != nullptr) {
|
|
masafumi-inoue |
26f824 |
refer_tile.getRaster()->unlock();
|
|
masafumi-inoue |
26f824 |
}
|
|
Shinya Kitaoka |
120a6e |
noise_tile.getRaster()->unlock();
|
|
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) {
|
|
masafumi-inoue |
26f824 |
if (refer_tile.getRaster() != nullptr) {
|
|
masafumi-inoue |
26f824 |
refer_tile.getRaster()->unlock();
|
|
masafumi-inoue |
26f824 |
}
|
|
Shinya Kitaoka |
120a6e |
noise_tile.getRaster()->unlock();
|
|
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 (...) {
|
|
masafumi-inoue |
26f824 |
if (refer_tile.getRaster() != nullptr) {
|
|
masafumi-inoue |
26f824 |
refer_tile.getRaster()->unlock();
|
|
masafumi-inoue |
26f824 |
}
|
|
Shinya Kitaoka |
120a6e |
noise_tile.getRaster()->unlock();
|
|
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 |
}
|