Skip to content

Commit

Permalink
save single camera in each bin file
Browse files Browse the repository at this point in the history
  • Loading branch information
Xinyu Li authored and Xinyu Li committed Apr 9, 2024
1 parent 09b6be4 commit ccf54ec
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 120 deletions.
52 changes: 14 additions & 38 deletions src/bb/image-io/bb.h
Original file line number Diff line number Diff line change
Expand Up @@ -1113,12 +1113,9 @@ class BinarySaver : public ion::BuildingBlock<BinarySaver<T, D>> {
BuildingBlockParam<std::string> output_directory_ptr{ "output_directory", "." };
BuildingBlockParam<int32_t> num_devices{"num_devices", 2};

Input<Halide::Func[]> input_images{ "input_images", Halide::type_of<T>(), D };

Input<Halide::Func[]> input_deviceinfo{ "input_deviceinfo", Halide::type_of<uint8_t>(), 1 };
Input<Halide::Func> input_images{"input", Halide::type_of<T>(), D};
Input<Halide::Func> input_deviceinfo{ "input_deviceinfo", Halide::type_of<uint8_t>(), 1 };
Input<Halide::Func> frame_count{ "frame_count", Halide::type_of<uint32_t>(), 1 };


Input<int32_t> width{ "width" };
Input<int32_t> height{ "height" };

Expand All @@ -1141,42 +1138,21 @@ class BinarySaver : public ion::BuildingBlock<BinarySaver<T, D>> {
int32_t dim = D;
int32_t byte_depth = sizeof(T);

Buffer<uint8_t> id_buf = this->get_id();
if (num_devices==1){
Func image;
image(_) = input_images(_);
image.compute_root();
Buffer<uint8_t> id_buf = this->get_id();

Func deviceinfo;
deviceinfo(_) = input_deviceinfo(_);
deviceinfo.compute_root();
Func image;
image(_) = input_images(_);
image.compute_root();

std::vector<ExternFuncArgument> params = {id_buf, image, deviceinfo, fc, width, height, dim, byte_depth, output_directory_buf };
Func ion_bb_image_io_binary_image_saver;
ion_bb_image_io_binary_image_saver.define_extern("ion_bb_image_io_binary_1image_saver", params, Int(32), 0);
ion_bb_image_io_binary_image_saver.compute_root();
output() = ion_bb_image_io_binary_image_saver();
}else if (num_devices==2){
Func image0, image1;
image0(_) = input_images[0](_);
image1(_) = input_images[1](_);
image0.compute_root();
image1.compute_root();
Func deviceinfo;
deviceinfo(_) = input_deviceinfo(_);
deviceinfo.compute_root();

Func deviceinfo0, deviceinfo1;
deviceinfo0(_) = input_deviceinfo[0](_);
deviceinfo1(_) = input_deviceinfo[1](_);
deviceinfo0.compute_root();
deviceinfo1.compute_root();

std::vector<ExternFuncArgument> params = {id_buf, image0, image1, deviceinfo0, deviceinfo1, fc, width, height, dim, byte_depth, output_directory_buf };
Func ion_bb_image_io_binary_image_saver;
ion_bb_image_io_binary_image_saver.define_extern("ion_bb_image_io_binary_2image_saver", params, Int(32), 0);
ion_bb_image_io_binary_image_saver.compute_root();
output() = ion_bb_image_io_binary_image_saver();
}else{
std::runtime_error("device number > 2 is not supported");
}
std::vector<ExternFuncArgument> params = {id_buf, image, deviceinfo, fc, width, height, dim, byte_depth, output_directory_buf };
Func ion_bb_image_io_binary_image_saver;
ion_bb_image_io_binary_image_saver.define_extern("ion_bb_image_io_binary_image_saver", params, Int(32), 0);
ion_bb_image_io_binary_image_saver.compute_root();
output(_) = ion_bb_image_io_binary_image_saver(_);

this->register_disposer("writer_dispose");
}
Expand Down
86 changes: 4 additions & 82 deletions src/bb/image-io/rt_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class Writer {

}

void post_images(std::vector<void *>& outs, std::vector<size_t>& size,
void post_image(std::vector<void *>& outs, std::vector<size_t>& size,
std::vector<ion::bb::image_io::rawHeader>& header_infos, void* framecounts)
{
if (with_header_){
Expand Down Expand Up @@ -474,7 +474,7 @@ int ion_bb_image_io_binary_1gendc_saver( halide_buffer_t * id_buf, halide_buffer
ION_REGISTER_EXTERN(ion_bb_image_io_binary_1gendc_saver);

extern "C" ION_EXPORT
int ion_bb_image_io_binary_1image_saver(
int ion_bb_image_io_binary_image_saver(
halide_buffer_t * id_buf,
halide_buffer_t * image, halide_buffer_t * deviceinfo, halide_buffer_t * frame_count,
int width, int height, int dim, int byte_depth, halide_buffer_t* output_directory_buf,
Expand Down Expand Up @@ -518,7 +518,7 @@ int ion_bb_image_io_binary_1image_saver(

std::vector<void *> obufs{image->host};
std::vector<size_t> size_in_bytes{image->size_in_bytes()};
w.post_images(obufs, size_in_bytes, header_infos, frame_count->host);
w.post_image(obufs, size_in_bytes, header_infos, frame_count->host);
}

return 0;
Expand All @@ -533,85 +533,7 @@ int ion_bb_image_io_binary_1image_saver(
}
}

ION_REGISTER_EXTERN(ion_bb_image_io_binary_1image_saver);

extern "C" ION_EXPORT
int ion_bb_image_io_binary_2image_saver(
halide_buffer_t * id_buf,
halide_buffer_t * image0, halide_buffer_t * image1,
halide_buffer_t * deviceinfo0, halide_buffer_t * deviceinfo1, halide_buffer_t * frame_count,
int32_t width, int32_t height, int32_t dim, int byte_depth, halide_buffer_t* output_directory_buf,
halide_buffer_t * out)
{
try {
int num_output = 2;
const std::string id(reinterpret_cast<const char *>(id_buf->host));
int32_t frame_size = dim == 2 ? width * height * byte_depth : width * height * 3 * byte_depth;
std::vector<int32_t>frame_size_list{frame_size, frame_size};
const ::std::string output_directory(reinterpret_cast<const char*>(output_directory_buf->host));
auto& w(Writer::get_instance(id, frame_size_list, output_directory, true));

if (image0->is_bounds_query() || deviceinfo0->is_bounds_query() ||
image1->is_bounds_query() || deviceinfo1->is_bounds_query() || frame_count->is_bounds_query()) {
if (image0->is_bounds_query()) {
image0->dim[0].min = 0;
image0->dim[0].extent = width;
image0->dim[1].min = 0;
image0->dim[1].extent = height;
if (dim == 3){
image0->dim[2].min = 0;
image0->dim[2].extent = 3;
}
}
if (deviceinfo0->is_bounds_query()) {
deviceinfo0->dim[0].min = 0;
deviceinfo0->dim[0].extent = sizeof(ion::bb::image_io::rawHeader);
}
if (image1->is_bounds_query()) {
image1->dim[0].min = 0;
image1->dim[0].extent = width;
image1->dim[1].min = 0;
image1->dim[1].extent = height;
if (dim == 3){
image1->dim[2].min = 0;
image1->dim[2].extent = 3;
}
}
if (deviceinfo1->is_bounds_query()) {
deviceinfo1->dim[0].min = 0;
deviceinfo1->dim[0].extent = sizeof(ion::bb::image_io::rawHeader);
}
if (frame_count->is_bounds_query()) {
frame_count->dim[0].min = 0;
frame_count->dim[0].extent = num_output;
}
return 0;
}
else {

ion::bb::image_io::rawHeader header_info0, header_info1;
::memcpy(&header_info0, deviceinfo0->host, sizeof(ion::bb::image_io::rawHeader));
::memcpy(&header_info1, deviceinfo1->host, sizeof(ion::bb::image_io::rawHeader));
std::vector<ion::bb::image_io::rawHeader> header_infos{header_info0, header_info1};

std::vector<void *> obufs{image0->host, image1->host};
std::vector<size_t> size_in_bytes{image0->size_in_bytes(), image1->size_in_bytes()};
w.post_images(obufs, size_in_bytes, header_infos, frame_count->host);
}

return 0;
}
catch (const ::std::exception& e) {
::std::cerr << e.what() << ::std::endl;
return -1;
}
catch (...) {
::std::cerr << "Unknown error" << ::std::endl;
return -1;
}
}

ION_REGISTER_EXTERN(ion_bb_image_io_binary_2image_saver);
ION_REGISTER_EXTERN(ion_bb_image_io_binary_image_saver);

namespace {

Expand Down

0 comments on commit ccf54ec

Please sign in to comment.