diff --git a/src/bb/image-io/bb.h b/src/bb/image-io/bb.h index eef0c33e..104e2d4f 100644 --- a/src/bb/image-io/bb.h +++ b/src/bb/image-io/bb.h @@ -831,13 +831,11 @@ class U3VCameraN : public ion::BuildingBlock> { public: BuildingBlockParam num_devices{"num_devices", 2}; BuildingBlockParam frame_sync{"frame_sync", false}; - - BuildingBlockParam gain_key_ptr{"gain_key", "Gain"}; - BuildingBlockParam exposure_key_ptr{"exposure_key", "Exposure"}; - BuildingBlockParam realtime_diaplay_mode{"realtime_diaplay_mode", false}; BuildingBlockParam enable_control{"enable_control", false}; + BuildingBlockParam gain_key_ptr{"gain_key", "Gain"}; + BuildingBlockParam exposure_key_ptr{"exposure_key", "Exposure"}; Output output{ "output", Halide::type_of(), D}; Output device_info{ "device_info", Halide::type_of(), 1}; @@ -874,7 +872,9 @@ class U3VCameraN : public ion::BuildingBlock> { std::vector params{ id_buf, - static_cast(frame_sync), static_cast(realtime_diaplay_mode), static_cast(enable_control), + static_cast(frame_sync), + static_cast(realtime_diaplay_mode), + static_cast(enable_control), gain_key_buf, exposure_key_buf }; @@ -951,28 +951,30 @@ using U3VCameraN_U16x2 = U3VCameraN; class U3VGenDC : public ion::BuildingBlock { public: BuildingBlockParam num_devices{"num_devices", 2}; - BuildingBlockParam frame_sync{"frame_sync", false}; - BuildingBlockParam gain_key_ptr{"gain_key", "Gain"}; - BuildingBlockParam exposure_key_ptr{"exposure_key", "Exposure"}; BuildingBlockParam realtime_diaplay_mode{"realtime_diaplay_mode", false}; - Input gain{ "gain", Halide::type_of(), 1}; - Input exposure{ "exposure", Halide::type_of(), 1}; + BuildingBlockParam enable_control{"enable_control", false}; + BuildingBlockParam gain_key_ptr{"gain_key", "Gain"}; + BuildingBlockParam exposure_key_ptr{"exposure_key", "Exposure"}; Output gendc{ "gendc", Halide::type_of(), 1}; Output device_info{ "device_info", Halide::type_of(), 1}; - void generate() { - using namespace Halide; + std::vector *> gain; + std::vector *> exposure; - Func gain_func; - gain_func(_) = gain(_); - gain_func.compute_root(); + void configure() { + if (enable_control) { + for (auto i=0; i("gain_" + std::to_string(i))); + exposure.push_back(Halide::Internal::GeneratorBase::add_input("exposure_" + std::to_string(i))); + } + } + } - Func exposure_func; - exposure_func(_) = exposure(_); - exposure_func.compute_root(); + void generate() { + using namespace Halide; Func u3v_gendc("u3v_gendc"); { @@ -989,11 +991,26 @@ class U3VGenDC : public ion::BuildingBlock { std::memcpy(exposure_key_buf.data(), exposure_key.c_str(), exposure_key.size()); std::vector params{ - static_cast(frame_sync), static_cast(realtime_diaplay_mode), - gain_func, exposure_func, - id_buf, gain_key_buf, exposure_key_buf + id_buf, + static_cast(frame_sync), + static_cast(realtime_diaplay_mode), + static_cast(enable_control), + gain_key_buf, exposure_key_buf }; + for (int i = 0; i(), 0.0)); + } + if (i < exposure.size()) { + params.push_back(*exposure[i]); + } else { + params.push_back(Internal::make_const(type_of(), 0.0)); + } + } + gendc.resize(num_devices); std::vector output_type; for (int i = 0; i < gendc.size(); i++) { diff --git a/src/bb/image-io/rt_u3v.h b/src/bb/image-io/rt_u3v.h index 7161527e..4f31c48b 100644 --- a/src/bb/image-io/rt_u3v.h +++ b/src/bb/image-io/rt_u3v.h @@ -1247,7 +1247,7 @@ extern "C" int ION_EXPORT ion_bb_image_io_u3v_camera2_frame_count( halide_buffer_t *, halide_buffer_t *, - int32_t num_sensor, bool frame_sync, bool realtime_display_mode, + int32_t num_sensor, bool frame_sync, bool realtime_display_mode, halide_buffer_t * id_buf, halide_buffer_t* out) { const std::string id(reinterpret_cast(id_buf->host)); return ion::bb::image_io::u3v_camera_frame_count(id, num_sensor, frame_sync, realtime_display_mode, out); @@ -1256,9 +1256,10 @@ ION_REGISTER_EXTERN(ion_bb_image_io_u3v_camera2_frame_count); extern "C" int ION_EXPORT ion_bb_image_io_u3v_gendc_camera1( - bool frame_sync, bool realtime_display_mode, - halide_buffer_t* gain, halide_buffer_t* exposure, - halide_buffer_t * id_buf, halide_buffer_t * gain_key_buf, halide_buffer_t * exposure_key_buf, + halide_buffer_t * id_buf, + bool frame_sync, bool realtime_display_mode, bool enable_control, + halide_buffer_t * gain_key_buf, halide_buffer_t * exposure_key_buf, + double gain0, double exposure0, halide_buffer_t * out_gendc ) { @@ -1269,22 +1270,17 @@ int ION_EXPORT ion_bb_image_io_u3v_gendc_camera1( const std::string gain_key(reinterpret_cast(gain_key_buf->host)); const std::string exposure_key(reinterpret_cast(exposure_key_buf->host)); auto &u3v(ion::bb::image_io::U3V::get_instance(id, num_output, false, realtime_display_mode)); - if (out_gendc->is_bounds_query() || gain->is_bounds_query() || exposure->is_bounds_query()) { - gain->dim[0].min = 0; - gain->dim[0].extent = num_output; - exposure->dim[0].min = 0; - exposure->dim[0].extent = num_output; + if (out_gendc->is_bounds_query()) { return 0; - }else{ - // set gain & exposure - for (int i = 0; i < num_output; ++i){ - u3v.SetGain(i, gain_key, (reinterpret_cast(gain->host))[i]); - u3v.SetExposure(i, exposure_key, (reinterpret_cast(exposure->host))[i]); - } - std::vector obufs{out_gendc->host}; - u3v.get_gendc(obufs); - } + // set gain & exposure + if (enable_control){ + ion::log::debug("Setting gain0:{} exposure0:{}", gain0, exposure0); + u3v.SetGain(0, gain_key, gain0); + u3v.SetExposure(0, exposure_key, exposure0); + } + std::vector obufs{out_gendc->host}; + u3v.get_gendc(obufs); return 0; } catch (const std::exception &e) { @@ -1299,33 +1295,35 @@ ION_REGISTER_EXTERN(ion_bb_image_io_u3v_gendc_camera1); extern "C" int ION_EXPORT ion_bb_image_io_u3v_gendc_camera2( - bool frame_sync, bool realtime_display_mode, - halide_buffer_t* gain, halide_buffer_t* exposure, - halide_buffer_t * id_buf, halide_buffer_t * gain_key_buf, halide_buffer_t * exposure_key_buf, - halide_buffer_t * gendc0, halide_buffer_t * gendc1 + halide_buffer_t * id_buf, + bool frame_sync, bool realtime_display_mode, bool enable_control, + halide_buffer_t * gain_key_buf, halide_buffer_t * exposure_key_buf, + double gain0, double exposure0, + double gain1, double exposure1, + halide_buffer_t * out_gendc0, halide_buffer_t * out_gendc1 ) { using namespace Halide; try { - int num_output = 2; const std::string id(reinterpret_cast(id_buf->host)); const std::string gain_key(reinterpret_cast(gain_key_buf->host)); const std::string exposure_key(reinterpret_cast(exposure_key_buf->host)); auto &u3v(ion::bb::image_io::U3V::get_instance(id, 2, frame_sync, realtime_display_mode)); - if (gendc0->is_bounds_query() || gendc1->is_bounds_query() || gain->is_bounds_query() || exposure->is_bounds_query()) { - gain->dim[0].min = 0; - gain->dim[0].extent = num_output; - exposure->dim[0].min = 0; - exposure->dim[0].extent = num_output; + if (out_gendc0->is_bounds_query() || out_gendc1->is_bounds_query() ) { return 0; }else{ // set gain & exposure - for (int i = 0; i < num_output; ++i){ - u3v.SetGain(i, gain_key, (reinterpret_cast(gain->host))[i]); - u3v.SetExposure(i, exposure_key, (reinterpret_cast(exposure->host))[i]); + if (enable_control) { + ion::log::debug("Setting gain0:{} exposure0:{}", gain0, exposure0); + u3v.SetGain(0, gain_key, gain0); + u3v.SetExposure(0, exposure_key, exposure0); + + ion::log::debug("Setting gain1:{} exposure1:{}", gain1, exposure1); + u3v.SetGain(1, gain_key, gain1); + u3v.SetExposure(1, exposure_key, exposure1); } - std::vector obufs{gendc0->host, gendc1->host}; + std::vector obufs{out_gendc0->host, out_gendc1->host}; u3v.get_gendc(obufs); }