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