2016-03-19 06:57:51 +13:00
|
|
|
#ifdef NDEBUG
|
|
|
|
|
2019-05-27 16:06:47 +12:00
|
|
|
/*------------------------------------------------------------------*/
|
2016-03-19 06:57:51 +13:00
|
|
|
#include <sstream> /* std::ostringstream */
|
|
|
|
#include "tfxparam.h"
|
|
|
|
#include "stdfx.h"
|
|
|
|
#include "tfxattributes.h"
|
|
|
|
#include "ino_common.h"
|
|
|
|
#include "igs_line_blur.h"
|
2019-05-27 16:06:47 +12:00
|
|
|
|
2016-06-29 18:17:12 +12:00
|
|
|
class ino_line_blur final : public TStandardRasterFx {
|
2016-06-15 18:43:10 +12:00
|
|
|
FX_PLUGIN_DECLARATION(ino_line_blur)
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2019-05-27 16:06:47 +12:00
|
|
|
TRasterFxPort m_input;
|
2016-06-15 18:43:10 +12:00
|
|
|
TIntEnumParamP m_b_action_mode;
|
|
|
|
TDoubleParamP m_b_blur_count;
|
|
|
|
TDoubleParamP m_b_blur_power;
|
|
|
|
TIntEnumParamP m_b_blur_subpixel;
|
|
|
|
TDoubleParamP m_b_blur_near_ref;
|
|
|
|
TDoubleParamP m_b_blur_near_len;
|
|
|
|
TDoubleParamP m_v_smooth_retry;
|
|
|
|
TDoubleParamP m_v_near_ref;
|
|
|
|
TDoubleParamP m_v_near_len;
|
|
|
|
TDoubleParamP m_b_smudge_thick;
|
|
|
|
TDoubleParamP m_b_smudge_remain;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
ino_line_blur()
|
|
|
|
: m_b_action_mode(new TIntEnumParam(0, "Blur"))
|
|
|
|
, m_b_blur_count(51)
|
|
|
|
, m_b_blur_power(1.0)
|
|
|
|
, m_b_blur_subpixel(new TIntEnumParam())
|
|
|
|
, m_b_blur_near_ref(5)
|
|
|
|
, m_b_blur_near_len(160)
|
|
|
|
, m_v_smooth_retry(100)
|
|
|
|
, m_v_near_ref(4)
|
|
|
|
, m_v_near_len(160)
|
|
|
|
, m_b_smudge_thick(7)
|
|
|
|
, m_b_smudge_remain(0.85) {
|
|
|
|
addInputPort("Source", this->m_input);
|
|
|
|
bindParam(this, "action_mode", this->m_b_action_mode);
|
|
|
|
bindParam(this, "blur_count", this->m_b_blur_count);
|
|
|
|
bindParam(this, "blur_power", this->m_b_blur_power);
|
|
|
|
bindParam(this, "blur_subpixel", this->m_b_blur_subpixel);
|
|
|
|
bindParam(this, "blur_near_ref", this->m_b_blur_near_ref);
|
|
|
|
bindParam(this, "blur_near_len", this->m_b_blur_near_len);
|
|
|
|
bindParam(this, "vector_smooth_retry", this->m_v_smooth_retry);
|
|
|
|
bindParam(this, "vector_near_ref", this->m_v_near_ref);
|
|
|
|
bindParam(this, "vector_near_len", this->m_v_near_len);
|
|
|
|
bindParam(this, "smudge_thick", this->m_b_smudge_thick);
|
|
|
|
bindParam(this, "smudge_remain", this->m_b_smudge_remain);
|
|
|
|
|
|
|
|
this->m_b_action_mode->addItem(1, "Smudge");
|
|
|
|
this->m_b_blur_count->setValueRange(1, 100);
|
|
|
|
this->m_b_blur_power->setValueRange(0.1, 10.0);
|
|
|
|
this->m_b_blur_subpixel->addItem(1, "1");
|
|
|
|
this->m_b_blur_subpixel->addItem(2, "4");
|
|
|
|
this->m_b_blur_subpixel->addItem(3, "9");
|
|
|
|
this->m_b_blur_subpixel->setDefaultValue(2);
|
|
|
|
this->m_b_blur_subpixel->setValue(2);
|
|
|
|
this->m_b_blur_near_ref->setValueRange(1, 100);
|
|
|
|
this->m_b_blur_near_len->setValueRange(1, 1000);
|
|
|
|
this->m_v_smooth_retry->setValueRange(1, 1000);
|
|
|
|
this->m_v_near_ref->setValueRange(1, 100);
|
|
|
|
this->m_v_near_len->setValueRange(1, 1000);
|
|
|
|
this->m_b_smudge_thick->setValueRange(1, 100);
|
|
|
|
this->m_b_smudge_remain->setValueRange(0.0, 1.0);
|
|
|
|
}
|
2019-05-27 16:06:47 +12:00
|
|
|
double get_render_real_radius(const double frame, const TAffine affine) {
|
|
|
|
double rad = this->m_b_blur_count->getValue(frame);
|
|
|
|
/*--- 単位について考察必要 ---*/
|
|
|
|
// rad *= ino::pixel_per_mm();
|
|
|
|
/*--- Geometryを反映させる ---*/
|
|
|
|
// TAffine aff(affine);
|
|
|
|
return rad;
|
|
|
|
}
|
|
|
|
void get_render_enlarge(const double frame, const TAffine affine,
|
|
|
|
TRectD &bBox) {
|
|
|
|
const int margin =
|
|
|
|
static_cast<int>(ceil(this->get_render_real_radius(frame, affine)));
|
|
|
|
if (0 < margin) {
|
|
|
|
bBox = bBox.enlarge(static_cast<double>(margin));
|
|
|
|
}
|
|
|
|
}
|
2020-09-16 09:49:57 +12:00
|
|
|
bool doGetBBox(double frame, TRectD &bBox, const TRenderSettings &info) override {
|
2016-06-15 18:43:10 +12:00
|
|
|
if (false == this->m_input.isConnected()) {
|
|
|
|
bBox = TRectD();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const bool ret = this->m_input->doGetBBox(frame, bBox, info);
|
2019-05-27 16:06:47 +12:00
|
|
|
this->get_render_enlarge(frame, info.m_affine, bBox);
|
2016-06-15 18:43:10 +12:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
int getMemoryRequirement(const TRectD &rect, double frame,
|
2020-09-16 09:49:57 +12:00
|
|
|
const TRenderSettings &info) override {
|
2016-06-15 18:43:10 +12:00
|
|
|
TRectD bBox(rect);
|
2019-05-27 16:06:47 +12:00
|
|
|
this->get_render_enlarge(frame, info.m_affine, bBox);
|
2016-06-15 18:43:10 +12:00
|
|
|
return TRasterFx::memorySize(bBox, info.m_bpp);
|
|
|
|
}
|
|
|
|
void transform(double frame, int port, const TRectD &rectOnOutput,
|
|
|
|
const TRenderSettings &infoOnOutput, TRectD &rectOnInput,
|
2020-09-16 09:49:57 +12:00
|
|
|
TRenderSettings &infoOnInput) override {
|
2016-06-15 18:43:10 +12:00
|
|
|
rectOnInput = rectOnOutput;
|
|
|
|
infoOnInput = infoOnOutput;
|
2019-05-27 16:06:47 +12:00
|
|
|
this->get_render_enlarge(frame, infoOnOutput.m_affine, rectOnInput);
|
2016-06-15 18:43:10 +12:00
|
|
|
}
|
2020-09-16 09:49:57 +12:00
|
|
|
bool canHandle(const TRenderSettings &info, double frame) override {
|
2016-06-15 18:43:10 +12:00
|
|
|
// return true;/* geometry処理済の画像に加工することになる */
|
|
|
|
return false; /* ここでの処理後にgeometryがかかる */
|
|
|
|
}
|
2020-09-16 09:49:57 +12:00
|
|
|
void doCompute(TTile &tile, double frame, const TRenderSettings &rend_sets) override;
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
2019-05-27 16:06:47 +12:00
|
|
|
|
2016-03-19 06:57:51 +13:00
|
|
|
FX_PLUGIN_IDENTIFIER(ino_line_blur, "inoLineBlurFx");
|
2019-05-27 16:06:47 +12:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
namespace {
|
2019-05-27 16:06:47 +12:00
|
|
|
void fx_(const TRasterP in_ras // no margin
|
2016-06-15 18:43:10 +12:00
|
|
|
,
|
|
|
|
TRasterP out_ras // no margin
|
|
|
|
,
|
2019-05-27 16:06:47 +12:00
|
|
|
const int action_mode, const int blur_count, const double blur_power,
|
|
|
|
const int blur_subpixel, const int blur_near_ref,
|
|
|
|
const int blur_near_len, const int vector_smooth_retry,
|
|
|
|
const int vector_near_ref, const int vector_near_len,
|
2016-06-15 18:43:10 +12:00
|
|
|
const int smudge_thick, const double smudge_remain) {
|
|
|
|
igs::line_blur::convert(
|
2021-06-08 12:41:43 +12:00
|
|
|
in_ras->getRawData(), // const void *in_no_margin (BGRA)
|
|
|
|
out_ras->getRawData(), // void *out_no_margin (BGRA)
|
|
|
|
in_ras->getLy(), // const int height_no_margin
|
|
|
|
in_ras->getLx(), // const int width_no_margin
|
|
|
|
in_ras->getWrap(), out_ras->getWrap(),
|
|
|
|
ino::channels(), // const int channels
|
|
|
|
ino::bits(in_ras), // const int bits
|
2019-05-27 16:06:47 +12:00
|
|
|
blur_count, blur_power, blur_subpixel, blur_near_ref, blur_near_len,
|
|
|
|
smudge_thick, smudge_remain, vector_smooth_retry, vector_near_ref,
|
2021-06-08 12:41:43 +12:00
|
|
|
vector_near_len, false, /* bool mv_sw false=OFF */
|
|
|
|
false, /* bool pv_sw false=OFF */
|
|
|
|
false, /* bool cv_sw false=OFF */
|
|
|
|
3, /* long reference_channel 3=Red:RGBA or Blue:BGRA */
|
|
|
|
false, /* bool debug_save_sw false=OFF */
|
2016-06-15 18:43:10 +12:00
|
|
|
action_mode);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
2019-05-27 16:06:47 +12:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
void ino_line_blur::doCompute(
|
2021-06-08 12:41:43 +12:00
|
|
|
TTile &tile, /* 注意:doGetBBox(-)が返す範囲の画像 */
|
2019-05-27 16:06:47 +12:00
|
|
|
double frame, const TRenderSettings &rend_sets) {
|
|
|
|
/*--- 接続していなければ処理しない -------------------------*/
|
2016-06-15 18:43:10 +12:00
|
|
|
if (!this->m_input.isConnected()) {
|
|
|
|
tile.getRaster()->clear(); /* 塗りつぶしクリア */
|
|
|
|
return;
|
|
|
|
}
|
2019-05-27 16:06:47 +12:00
|
|
|
/*--- サポートしていないPixelタイプはエラーを投げる --------*/
|
2016-06-15 18:43:10 +12:00
|
|
|
if (!((TRaster32P)tile.getRaster()) && !((TRaster64P)tile.getRaster())) {
|
|
|
|
throw TRopException("unsupported input pixel type");
|
|
|
|
}
|
2019-05-27 16:06:47 +12:00
|
|
|
/*--- パラメータを得る -------------------------------------*/
|
|
|
|
const int action_mode = this->m_b_action_mode->getValue();
|
|
|
|
const int blur_count = this->m_b_blur_count->getValue(frame);
|
|
|
|
const double blur_power = this->m_b_blur_power->getValue(frame);
|
|
|
|
const int blur_subpixel = this->m_b_blur_subpixel->getValue();
|
|
|
|
const int blur_near_ref = this->m_b_blur_near_ref->getValue(frame);
|
|
|
|
const int blur_near_len = this->m_b_blur_near_len->getValue(frame);
|
2016-06-15 18:43:10 +12:00
|
|
|
const int vector_smooth_retry = this->m_v_smooth_retry->getValue(frame);
|
|
|
|
const int vector_near_ref = this->m_v_near_ref->getValue(frame);
|
|
|
|
const int vector_near_len = this->m_v_near_len->getValue(frame);
|
2019-05-27 16:06:47 +12:00
|
|
|
const int smudge_thick = this->m_b_smudge_thick->getValue(frame);
|
|
|
|
const double smudge_remain = this->m_b_smudge_remain->getValue(frame);
|
|
|
|
/*--- 表示の範囲を得る -------------------------------------*/
|
2016-06-15 18:43:10 +12:00
|
|
|
TRectD bBox =
|
2021-06-08 12:41:43 +12:00
|
|
|
TRectD(tile.m_pos, /* Render画像上(Pixel単位)の位置 */
|
2016-06-15 18:43:10 +12:00
|
|
|
TDimensionD(/* Render画像上(Pixel単位)のサイズ */
|
|
|
|
tile.getRaster()->getLx(), tile.getRaster()->getLy()));
|
2019-05-27 16:06:47 +12:00
|
|
|
/*--- doGetBBox(-)が返す範囲の画像を生成 -------------------*/
|
|
|
|
TTile in_tile;
|
2016-06-15 18:43:10 +12:00
|
|
|
this->m_input->allocateAndCompute(
|
2019-05-27 16:06:47 +12:00
|
|
|
in_tile, bBox.getP00(),
|
2016-06-15 18:43:10 +12:00
|
|
|
TDimensionI(/* Pixel単位に四捨五入 */
|
|
|
|
static_cast<int>(bBox.getLx() + 0.5),
|
|
|
|
static_cast<int>(bBox.getLy() + 0.5)),
|
|
|
|
tile.getRaster(), frame, rend_sets);
|
2019-05-27 16:06:47 +12:00
|
|
|
/*--- 保存すべき画像メモリを塗りつぶしクリア ---------------*/
|
|
|
|
tile.getRaster()->clear();
|
|
|
|
/*--- 画像処理 ---------------------------------------------*/
|
2016-06-15 18:43:10 +12:00
|
|
|
try {
|
|
|
|
tile.getRaster()->lock();
|
2019-05-27 16:06:47 +12:00
|
|
|
fx_(in_tile.getRaster() // in no margin
|
2016-06-15 18:43:10 +12:00
|
|
|
,
|
2019-05-27 16:06:47 +12:00
|
|
|
tile.getRaster() // out no margin
|
2016-06-15 18:43:10 +12:00
|
|
|
,
|
2019-05-27 16:06:47 +12:00
|
|
|
action_mode, blur_count, blur_power, blur_subpixel, blur_near_ref,
|
|
|
|
blur_near_len, vector_smooth_retry, vector_near_ref, vector_near_len,
|
2016-06-15 18:43:10 +12:00
|
|
|
smudge_thick, smudge_remain);
|
|
|
|
tile.getRaster()->unlock();
|
|
|
|
}
|
2019-05-27 16:06:47 +12:00
|
|
|
/*--- error処理 --------------------------------------------*/
|
2021-06-08 12:41:43 +12:00
|
|
|
catch (std::bad_alloc &) {
|
2016-06-15 18:43:10 +12:00
|
|
|
tile.getRaster()->unlock();
|
|
|
|
throw;
|
2021-06-08 12:41:43 +12:00
|
|
|
} catch (std::exception &) {
|
2016-06-15 18:43:10 +12:00
|
|
|
tile.getRaster()->unlock();
|
|
|
|
throw;
|
|
|
|
} catch (...) {
|
|
|
|
tile.getRaster()->unlock();
|
|
|
|
throw;
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
#endif
|