| #include <sstream> /* std::ostringstream */ |
| #include "tfxparam.h" |
| #include "stdfx.h" |
| |
| #include "ino_common.h" |
| |
| class ino_hls_noise : public TStandardRasterFx |
| { |
| FX_PLUGIN_DECLARATION(ino_hls_noise) |
| TRasterFxPort m_input; |
| TRasterFxPort m_refer; |
| |
| TDoubleParamP m_hue; |
| TDoubleParamP m_lig; |
| TDoubleParamP m_sat; |
| TDoubleParamP m_mat; |
| TDoubleParamP m_random_seed; |
| TDoubleParamP m_near_blur; |
| TDoubleParamP m_term_effective; |
| TDoubleParamP m_term_center; |
| TIntEnumParamP m_term_type; |
| |
| TBoolParamP m_anti_alias; |
| TIntEnumParamP m_ref_mode; |
| |
| public: |
| ino_hls_noise() |
| : m_hue(0.025 * ino::param_range()), m_lig(0.035 * ino::param_range()), m_sat(0.0 * ino::param_range()), m_mat(0.0 * ino::param_range()), m_random_seed(1), m_near_blur(1.0 * ino::param_range()), m_term_effective(0.0 * ino::param_range()), m_term_center(ino::param_range() / 2.0), m_term_type(new TIntEnumParam(0, "Keep Noise")) |
| |
| , |
| m_anti_alias(true), m_ref_mode(new TIntEnumParam(0, "Red")) |
| { |
| addInputPort("Source", this->m_input); |
| addInputPort("Reference", this->m_refer); |
| |
| bindParam(this, "hue", this->m_hue); |
| bindParam(this, "lightness", this->m_lig); |
| bindParam(this, "saturation", this->m_sat); |
| bindParam(this, "alpha", this->m_mat); |
| bindParam(this, "seed", this->m_random_seed); |
| bindParam(this, "nblur", this->m_near_blur); |
| bindParam(this, "effective", this->m_term_effective); |
| bindParam(this, "center", this->m_term_center); |
| bindParam(this, "type", this->m_term_type); |
| |
| bindParam(this, "anti_alias", this->m_anti_alias); |
| bindParam(this, "reference", this->m_ref_mode); |
| |
| this->m_hue->setValueRange( |
| 0.0 * ino::param_range(), 1.0 * ino::param_range()); |
| this->m_lig->setValueRange( |
| 0.0 * ino::param_range(), 1.0 * ino::param_range()); |
| this->m_sat->setValueRange( |
| 0.0 * ino::param_range(), 1.0 * ino::param_range()); |
| this->m_mat->setValueRange( |
| 0.0 * ino::param_range(), 1.0 * ino::param_range()); |
| |
| this->m_random_seed->setValueRange( |
| 0, std::numeric_limits<unsigned long>::max()); |
| this->m_near_blur->setValueRange( |
| 0.0 * ino::param_range(), 1.0 * ino::param_range()); |
| this->m_term_effective->setValueRange( |
| 0.0 * ino::param_range(), 1.0 * ino::param_range()); |
| this->m_term_center->setValueRange( |
| 0.0 * ino::param_range(), 1.0 * ino::param_range()); |
| this->m_term_type->addItem(1, "Keep Contrast"); |
| |
| this->m_ref_mode->addItem(1, "Green"); |
| this->m_ref_mode->addItem(2, "Blue"); |
| this->m_ref_mode->addItem(3, "Alpha"); |
| this->m_ref_mode->addItem(4, "Luminance"); |
| this->m_ref_mode->addItem(-1, "Nothing"); |
| } |
| bool doGetBBox( |
| double frame, TRectD &bBox, const TRenderSettings &info) |
| { |
| if (this->m_input.isConnected()) { |
| return this->m_input->doGetBBox(frame, bBox, info); |
| } else { |
| bBox = TRectD(); |
| return false; |
| } |
| } |
| bool canHandle(const TRenderSettings &info, double frame) |
| { |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| return false; |
| } |
| void doCompute( |
| TTile &tile, double frame, const TRenderSettings &rend_sets); |
| }; |
| FX_PLUGIN_IDENTIFIER(ino_hls_noise, "inohlsNoiseFx"); |
| |
| #include "igs_hls_noise.h" |
| namespace |
| { |
| void fx_( |
| TRasterP in_ras, const TRasterP refer_ras, const int ref_mode |
| |
| , |
| double hue_range, double lig_range, double sat_range, double alp_range, unsigned long random_seed, double near_blur, double effective, double center, int type, const int camera_x, const int camera_y, const int camera_w, const int camera_h, const bool anti_alias_sw) |
| { |
| TRasterGR8P in_gr8( |
| in_ras->getLy(), in_ras->getLx() * ino::channels() * |
| ((TRaster64P)in_ras ? sizeof(unsigned short) : sizeof(unsigned char))); |
| in_gr8->lock(); |
| ino::ras_to_arr(in_ras, ino::channels(), in_gr8->getRawData()); |
| |
| |
| igs::hls_noise::change( |
| |
| in_gr8->getRawData() |
| |
| , |
| in_ras->getLy(), in_ras->getLx() |
| , |
| ino::channels(), ino::bits(in_ras) |
| |
| , |
| (((0 <= ref_mode) && (0 != refer_ras)) ? refer_ras->getRawData() : 0) |
| , |
| (((0 <= ref_mode) && (0 != refer_ras)) ? ino::bits(refer_ras) : 0), ref_mode |
| |
| , |
| camera_x, camera_y, camera_w, camera_h |
| |
| , |
| hue_range, lig_range, sat_range, alp_range, random_seed, near_blur, effective, center, type, effective, center, type, effective, center, type, anti_alias_sw); |
| |
| ino::arr_to_ras(in_gr8->getRawData(), ino::channels(), in_ras, 0); |
| in_gr8->unlock(); |
| } |
| } |
| |
| void ino_hls_noise::doCompute( |
| TTile &tile, double frame, const TRenderSettings &rend_sets) |
| { |
| |
| if (!this->m_input.isConnected()) { |
| tile.getRaster()->clear(); |
| return; |
| } |
| |
| |
| if (!((TRaster32P)tile.getRaster()) && |
| !((TRaster64P)tile.getRaster())) { |
| throw TRopException("unsupported input pixel type"); |
| } |
| |
| |
| const double hue_range = this->m_hue->getValue(frame) / |
| ino::param_range(); |
| const double lig_range = this->m_lig->getValue(frame) / |
| ino::param_range(); |
| const double sat_range = this->m_sat->getValue(frame) / |
| ino::param_range(); |
| const double mat_range = this->m_mat->getValue(frame) / |
| ino::param_range(); |
| const unsigned long random_seed = static_cast<unsigned long>( |
| this->m_random_seed->getValue(frame)); |
| const double near_blur = this->m_near_blur->getValue(frame) / |
| ino::param_range() / 2.0; |
| int term_type = -1; |
| switch (this->m_term_type->getValue()) { |
| case 0: |
| term_type = 0; |
| break; |
| case 1: |
| term_type = 3; |
| break; |
| } |
| const double term_center = this->m_term_center->getValue(frame) / |
| ino::param_range(); |
| const double term_effective = |
| this->m_term_effective->getValue(frame) / |
| ino::param_range(); |
| const bool anti_alias_sw = this->m_anti_alias->getValue(); |
| const int ref_mode = this->m_ref_mode->getValue(); |
| |
| |
| this->m_input->compute(tile, frame, rend_sets); |
| |
| int camera_x = 0; |
| int camera_y = 0; |
| int camera_w = static_cast<int>(rend_sets.m_cameraBox.getLx() + 0.5); |
| int camera_h = static_cast<int>(rend_sets.m_cameraBox.getLy() + 0.5); |
| |
| const int margin_w = tile.getRaster()->getLx() - camera_w; |
| const int margin_h = tile.getRaster()->getLy() - camera_h; |
| if ((0 <= margin_h && 0 < margin_w) |
| || (0 < margin_h && 0 <= margin_w) |
| || (0 < margin_h && 0 < margin_w) |
| ) { |
| |
| |
| camera_x = margin_w / 2; |
| camera_y = margin_h / 2; |
| camera_w = rend_sets.m_cameraBox.getLx(); |
| camera_h = rend_sets.m_cameraBox.getLy(); |
| } |
| |
| |
| else { |
| camera_w = tile.getRaster()->getLx(); |
| camera_h = tile.getRaster()->getLy(); |
| } |
| |
| TTile reference_tile; |
| bool reference_sw = false; |
| if (this->m_refer.isConnected()) { |
| reference_sw = true; |
| this->m_refer->allocateAndCompute( |
| reference_tile, tile.m_pos, TDimensionI( |
| tile.getRaster()->getLx(), tile.getRaster()->getLy()), |
| tile.getRaster(), frame, rend_sets); |
| } |
| |
| const bool log_sw = ino::log_enable_sw(); |
| |
| if (log_sw) { |
| std::ostringstream os; |
| os << "params" |
| << " h " << hue_range |
| << " l " << lig_range |
| << " s " << sat_range |
| << " a " << mat_range |
| << " seed " << random_seed |
| << " nblur " << near_blur |
| << " effective " << term_effective |
| << " center " << term_center |
| << " type " << term_type |
| << " frame " << frame |
| << " anti_alias " << anti_alias_sw |
| << " reference " << ref_mode |
| << " pixbits " << ino::pixel_bits(tile.getRaster()) |
| << " tile.m_pos " << tile.m_pos |
| << " tile_getLx " << tile.getRaster()->getLx() |
| << " y " << tile.getRaster()->getLy() |
| << " rend_sets.m_cameraBox " << rend_sets.m_cameraBox |
| << " rend_sets.m_affine " << rend_sets.m_affine |
| << " camera x " << camera_x |
| << " y " << camera_y |
| << " w " << camera_w |
| << " h " << camera_h; |
| if (reference_sw) { |
| os |
| << " reference_tile.m_pos " << reference_tile.m_pos |
| << " reference_tile_getLx " << reference_tile.getRaster()->getLx() |
| << " y " << reference_tile.getRaster()->getLy(); |
| } |
| } |
| |
| try { |
| tile.getRaster()->lock(); |
| reference_tile.getRaster()->lock(); |
| fx_( |
| tile.getRaster(), reference_tile.getRaster(), ref_mode |
| |
| , |
| hue_range, lig_range, sat_range, mat_range, random_seed, near_blur, term_effective, term_center, term_type, camera_x, camera_y, camera_w, camera_h, anti_alias_sw |
| ); |
| reference_tile.getRaster()->unlock(); |
| tile.getRaster()->unlock(); |
| } |
| |
| catch (std::bad_alloc &e) { |
| reference_tile.getRaster()->unlock(); |
| tile.getRaster()->unlock(); |
| if (log_sw) { |
| std::string str("std::bad_alloc <"); |
| str += e.what(); |
| str += '>'; |
| } |
| throw; |
| } catch (std::exception &e) { |
| reference_tile.getRaster()->unlock(); |
| tile.getRaster()->unlock(); |
| if (log_sw) { |
| std::string str("exception <"); |
| str += e.what(); |
| str += '>'; |
| } |
| throw; |
| } catch (...) { |
| reference_tile.getRaster()->unlock(); |
| tile.getRaster()->unlock(); |
| if (log_sw) { |
| std::string str("other exception"); |
| } |
| throw; |
| } |
| } |