Elaboradar  0.1

◆ write_image()

void elaboradar::Assets::write_image ( const radarelab::Matrix2D< unsigned char > &  image,
const char *  dir_env_var,
const char *  ext,
const char *  desc 
)

Write an image in a raw file in ${dir_env_var}, with the acquisition date as file name and the given extension.

Image matrix is tranformed in out_image(x,image.cols()-1-y) = image(y, x);

Parametri
[in]image- Matrix2D to be written
[in]dir_env_var- file path
[in]ext- file extension
[out]desc- used to get better error messages.

Definizione alla linea 540 del file assets.cpp.

541 {
542  const char* dir = getenv(dir_env_var);
543  if (!dir)
544  {
545  LOG_INFO("$%s not set", dir_env_var);
546  throw runtime_error("required env var is not set");
547  }
548 
549  string fname = string(dir) + "/" + fname_from_acq_time() + ext;
550  FILE* out = fopen_checked(fname.c_str(), "wb", desc);
551 
552  LOG_INFO("aperto file %s dimensione matrice %zd\n", fname.c_str(), image.size());
553 
554  // Convert to south-north columns scanned west to east
555  Matrix2D<unsigned char> transformed(image.cols(), image.rows());
556  for (unsigned y = 0; y < image.cols(); ++y)
557  for (unsigned x = 0; x < image.rows(); ++x)
558  transformed(x, image.cols()-1-y) = image(y, x);
559  if (fwrite(transformed.data(), transformed.size(), 1, out) != 1)
560  {
561  LOG_WARN("cannot write to %s: %s", fname.c_str(), strerror(errno));
562  fclose(out);
563  throw std::runtime_error("cannot write to image file");
564  }
565 
566  fclose(out);
567 }
std::string fname_from_acq_time() const
Build a basename (without extension) for a file given the current acquisition time.
Definition: assets.cpp:531
FILE * fopen_checked(const char *fname, const char *mode, const char *description)
A wrapper of fopen that throws an exception if it cannot open the file.
Definition: utils.cpp:144

Referenzia fname_from_acq_time(), e radarelab::fopen_checked().