diff --git a/src/bb/image-io/bb.h b/src/bb/image-io/bb.h index d3b707d8..2f68a0b9 100644 --- a/src/bb/image-io/bb.h +++ b/src/bb/image-io/bb.h @@ -192,6 +192,110 @@ class D435 : public ion::BuildingBlock { } }; + +class GenericV4L2Bayer : public ion::BuildingBlock { +public: + GeneratorParam gc_title{"gc_title", "GenericV4L2Bayer"}; + GeneratorParam gc_description{"gc_description", "This captures Bayer image from V4L2."}; + GeneratorParam gc_tags{"gc_tags", "input,sensor"}; + GeneratorParam gc_inference{"gc_inference", R"((function(v){ return { output: [parseInt(v.width), parseInt(v.height)] }}))"}; + GeneratorParam gc_mandatory{"gc_mandatory", "width,height"}; + GeneratorParam gc_strategy{"gc_strategy", "self"}; + GeneratorParam gc_prefix{"gc_prefix", ""}; + + GeneratorParam index{"index", 0}; + GeneratorParam url{"url", ""}; + GeneratorParam fps{"fps", 20}; + GeneratorParam width{"width", 0}; + GeneratorParam height{"height", 0}; + GeneratorParam bit_width{"bit_width", 10}; + GeneratorParam bayer_pattern{"bayer_pattern", BayerMap::Pattern::RGGB, BayerMap::enum_map}; + GeneratorOutput output{"output", Halide::type_of(), 2}; + + void generate() { + using namespace Halide; + + std::string url_str = url; + Halide::Buffer url_buf(url_str.size() + 1); + url_buf.fill(0); + std::memcpy(url_buf.data(), url_str.c_str(), url_str.size()); + + std::vector params = { + instance_id++, + cast(index), + cast(fps), + cast(width), + cast(height), + Expr(make_pixel_format(bayer_pattern, bit_width)), + cast(0), + url_buf, + 1.f, 1.f, 1.f, + 0.f, + cast(bit_width), 16 - bit_width + }; + Func v4l2(static_cast(gc_prefix) + "output"); + v4l2.define_extern("ion_bb_image_io_v4l2", params, type_of(), 2); + v4l2.compute_root(); + + output = v4l2; + } +}; + +class CameraSimulation : public ion::BuildingBlock { +public: + GeneratorParam gc_title{"gc_title", "CameraSimulation"}; + GeneratorParam gc_description{"gc_description", "This simulates Bayer image."}; + GeneratorParam gc_tags{"gc_tags", "input,sensor"}; + GeneratorParam gc_inference{"gc_inference", R"((function(v){ return { output: [parseInt(v.width), parseInt(v.height)] }}))"}; + GeneratorParam gc_mandatory{"gc_mandatory", "width,height,url"}; + GeneratorParam gc_strategy{"gc_strategy", "self"}; + GeneratorParam gc_prefix{"gc_prefix", ""}; + + GeneratorParam fps{"fps", 30}; + GeneratorParam width{"width", 0}; + GeneratorParam height{"height", 0}; + GeneratorParam url{"url", ""}; + GeneratorParam bayer_pattern{"bayer_pattern", BayerMap::Pattern::RGGB, BayerMap::enum_map}; + GeneratorParam bit_width{"bit_width", 10}; + GeneratorParam bit_shift{"bit_shift", 0}; + GeneratorParam gain_r{"gain_r", 1.f}; + GeneratorParam gain_g{"gain_g", 1.f}; + GeneratorParam gain_b{"gain_b", 1.f}; + GeneratorParam offset{"offset", 0.f}; + + GeneratorOutput output{"output", Halide::type_of(), 2}; + + void generate() { + using namespace Halide; + std::string url_str = url; + Halide::Buffer url_buf(url_str.size() + 1); + url_buf.fill(0); + std::memcpy(url_buf.data(), url_str.c_str(), url_str.size()); + + std::vector params = { + instance_id++, + 0, + cast(fps), + cast(width), + cast(height), + Expr(make_pixel_format(bayer_pattern, bit_width)), + cast(1), + url_buf, + cast(gain_r), cast(gain_g), cast(gain_b), + cast(offset), + cast(bit_width), cast(bit_shift) + }; + Func camera(static_cast(gc_prefix) + "output"); + camera.define_extern("ion_bb_image_io_v4l2", params, type_of(), 2); + camera.compute_root(); + + output = camera; + } +}; +#endif + +int instance_id = 0; + class Camera : public ion::BuildingBlock { public: GeneratorParam gc_title{"gc_title", "USBCamera"}; @@ -319,7 +423,6 @@ class Camera2 : public ion::BuildingBlock { }; - class CameraN : public ion::BuildingBlock { public: GeneratorParam num_devices{"num_devices", 2}; @@ -400,108 +503,6 @@ class CameraN : public ion::BuildingBlock { }; - -class GenericV4L2Bayer : public ion::BuildingBlock { -public: - GeneratorParam gc_title{"gc_title", "GenericV4L2Bayer"}; - GeneratorParam gc_description{"gc_description", "This captures Bayer image from V4L2."}; - GeneratorParam gc_tags{"gc_tags", "input,sensor"}; - GeneratorParam gc_inference{"gc_inference", R"((function(v){ return { output: [parseInt(v.width), parseInt(v.height)] }}))"}; - GeneratorParam gc_mandatory{"gc_mandatory", "width,height"}; - GeneratorParam gc_strategy{"gc_strategy", "self"}; - GeneratorParam gc_prefix{"gc_prefix", ""}; - - GeneratorParam index{"index", 0}; - GeneratorParam url{"url", ""}; - GeneratorParam fps{"fps", 20}; - GeneratorParam width{"width", 0}; - GeneratorParam height{"height", 0}; - GeneratorParam bit_width{"bit_width", 10}; - GeneratorParam bayer_pattern{"bayer_pattern", BayerMap::Pattern::RGGB, BayerMap::enum_map}; - GeneratorOutput output{"output", Halide::type_of(), 2}; - - void generate() { - using namespace Halide; - - std::string url_str = url; - Halide::Buffer url_buf(url_str.size() + 1); - url_buf.fill(0); - std::memcpy(url_buf.data(), url_str.c_str(), url_str.size()); - - std::vector params = { - instance_id++, - cast(index), - cast(fps), - cast(width), - cast(height), - Expr(make_pixel_format(bayer_pattern, bit_width)), - cast(0), - url_buf, - 1.f, 1.f, 1.f, - 0.f, - cast(bit_width), 16 - bit_width - }; - Func v4l2(static_cast(gc_prefix) + "output"); - v4l2.define_extern("ion_bb_image_io_v4l2", params, type_of(), 2); - v4l2.compute_root(); - - output = v4l2; - } -}; - -class CameraSimulation : public ion::BuildingBlock { -public: - GeneratorParam gc_title{"gc_title", "CameraSimulation"}; - GeneratorParam gc_description{"gc_description", "This simulates Bayer image."}; - GeneratorParam gc_tags{"gc_tags", "input,sensor"}; - GeneratorParam gc_inference{"gc_inference", R"((function(v){ return { output: [parseInt(v.width), parseInt(v.height)] }}))"}; - GeneratorParam gc_mandatory{"gc_mandatory", "width,height,url"}; - GeneratorParam gc_strategy{"gc_strategy", "self"}; - GeneratorParam gc_prefix{"gc_prefix", ""}; - - GeneratorParam fps{"fps", 30}; - GeneratorParam width{"width", 0}; - GeneratorParam height{"height", 0}; - GeneratorParam url{"url", ""}; - GeneratorParam bayer_pattern{"bayer_pattern", BayerMap::Pattern::RGGB, BayerMap::enum_map}; - GeneratorParam bit_width{"bit_width", 10}; - GeneratorParam bit_shift{"bit_shift", 0}; - GeneratorParam gain_r{"gain_r", 1.f}; - GeneratorParam gain_g{"gain_g", 1.f}; - GeneratorParam gain_b{"gain_b", 1.f}; - GeneratorParam offset{"offset", 0.f}; - - GeneratorOutput output{"output", Halide::type_of(), 2}; - - void generate() { - using namespace Halide; - std::string url_str = url; - Halide::Buffer url_buf(url_str.size() + 1); - url_buf.fill(0); - std::memcpy(url_buf.data(), url_str.c_str(), url_str.size()); - - std::vector params = { - instance_id++, - 0, - cast(fps), - cast(width), - cast(height), - Expr(make_pixel_format(bayer_pattern, bit_width)), - cast(1), - url_buf, - cast(gain_r), cast(gain_g), cast(gain_b), - cast(offset), - cast(bit_width), cast(bit_shift) - }; - Func camera(static_cast(gc_prefix) + "output"); - camera.define_extern("ion_bb_image_io_v4l2", params, type_of(), 2); - camera.compute_root(); - - output = camera; - } -}; -#endif - class GUIDisplay : public ion::BuildingBlock { public: GeneratorParam gc_title{"gc_title", "GUI Display"}; @@ -585,6 +586,7 @@ class FBDisplay : public ion::BuildingBlock { output = display; } }; +#endif class GrayscaleDataLoader : public ion::BuildingBlock { public: @@ -660,7 +662,7 @@ class ColorDataLoader : public ion::BuildingBlock { output = color_data_loader; } }; -#endif + class ImageSaver : public ion::BuildingBlock { public: @@ -1199,16 +1201,16 @@ class BinaryLoader : public ion::BuildingBlock { ION_REGISTER_BUILDING_BLOCK(ion::bb::image_io::IMX219, image_io_imx219); ION_REGISTER_BUILDING_BLOCK(ion::bb::image_io::D435, image_io_d435); -ION_REGISTER_BUILDING_BLOCK(ion::bb::image_io::Camera, image_io_camera); -ION_REGISTER_BUILDING_BLOCK(ion::bb::image_io::Camera2, image_io_camera2); -ION_REGISTER_BUILDING_BLOCK(ion::bb::image_io::CameraN, image_io_cameraN); - ION_REGISTER_BUILDING_BLOCK(ion::bb::image_io::GenericV4L2Bayer, image_io_generic_v4l2_bayer); ION_REGISTER_BUILDING_BLOCK(ion::bb::image_io::CameraSimulation, image_io_camera_simulation); ION_REGISTER_BUILDING_BLOCK(ion::bb::image_io::FBDisplay, image_io_fb_display); +#endif + +ION_REGISTER_BUILDING_BLOCK(ion::bb::image_io::Camera, image_io_camera); +ION_REGISTER_BUILDING_BLOCK(ion::bb::image_io::Camera2, image_io_camera2); +ION_REGISTER_BUILDING_BLOCK(ion::bb::image_io::CameraN, image_io_cameraN); ION_REGISTER_BUILDING_BLOCK(ion::bb::image_io::ColorDataLoader, image_io_color_data_loader); ION_REGISTER_BUILDING_BLOCK(ion::bb::image_io::GrayscaleDataLoader, image_io_grayscale_data_loader); -#endif ION_REGISTER_BUILDING_BLOCK(ion::bb::image_io::GUIDisplay, image_io_gui_display); ION_REGISTER_BUILDING_BLOCK(ion::bb::image_io::ImageSaver, image_io_image_saver);