Elaboradar  0.1
 Tutto Classi Namespace File Funzioni Variabili Tipi enumerati (enum) Gruppi
void elaboradar::Assets::write_subimage ( const radarelab::Matrix2D< unsigned char > &  image,
unsigned  image_side,
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]image_side- write only the square central part of the original image, with this size in pixels of the image side
[in]dir_env_var- file path
[in]ext- file extension
[out]desc- used to get better error messages.

Definizione alla linea 572 del file assets.cpp.

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

573 {
574  const char* dir = getenv(dir_env_var);
575  if (!dir)
576  {
577  LOG_INFO("$%s not set", dir_env_var);
578  throw runtime_error("required env var is not set");
579  }
580 
581  string fname = string(dir) + "/" + fname_from_acq_time() + "_" + std::to_string(image_side) + ext;
582  FILE* out = fopen_checked(fname.c_str(), "wb", desc);
583 
584  LOG_INFO("aperto file %s dimensione matrice %zd\n", fname.c_str(), image.size());
585 
586  // Convert to south-north columns scanned west to east
587  unsigned xofs = (image.cols() - image_side) / 2;
588  unsigned yofs = (image.rows() - image_side) / 2;
589  //LOG_INFO(" Image_size %4d , Image.cols %4d Image.Rows %4d -- xofs %d yofs %d", image_side, image.cols(), image.rows(), xofs, yofs);
590  Matrix2D<unsigned char> transformed(image_side, image_side);
591  for (unsigned y = 0; y < image_side; ++y)
592  for (unsigned x = 0; x < image_side; ++x)
593  transformed(x, image_side-1-y) = image(y + yofs, x + xofs);
594 
595  if (fwrite(transformed.data(), transformed.size(), 1, out) != 1)
596  {
597  LOG_WARN("cannot write to %s: %s", fname.c_str(), strerror(errno));
598  fclose(out);
599  throw std::runtime_error("cannot write to image file");
600  }
601 
602  fclose(out);
603 }
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
std::string fname_from_acq_time() const
Build a basename (without extension) for a file given the current acquisition time.
Definition: assets.cpp:529