File: test_ics2a.cpp

package info (click to toggle)
libics 1.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,196 kB
  • sloc: ansic: 8,873; sh: 4,461; cpp: 770; makefile: 148
file content (55 lines) | stat: -rw-r--r-- 1,575 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <iostream>
#include <memory>
#include <cstdint>
#include <cstring>
#include "libics.hpp"

int main(int argc, const char* argv[]) {
   if (argc != 3) {
      std::cerr << "Two file names required: in out\n";
      exit(-1);
   }

   try {

      // Read image
      ics::ICS ip(argv[1], "r");
      auto layout = ip.GetLayout();
      std::size_t bufsize = ip.GetDataSize();
      std::unique_ptr<std::uint8_t[]> buf1{new std::uint8_t[bufsize]};
      ip.GetData(buf1.get(), bufsize);
      ip.Close();

      // Write image
      ip.Open(argv[2], "w2");
      ip.SetLayout(layout.dataType, layout.dimensions);
      std::string datafile{argv[1]};
      auto pos = datafile.rfind('.');
      if (pos != std::string::npos) {
         datafile.erase(pos);
      }
      datafile += ".ids";
      ip.SetSource(datafile, 0);
      ip.SetByteOrder(ics::ByteOrder::LittleEndian);
      ip.SetCompression(ics::Compression::Uncompressed, 0);
      ip.Close();

      // Read image
      ip.Open(argv[2], "r");
      if (bufsize != ip.GetDataSize()) {
         std::cerr << "Data in output file not same size as written.\n";
         exit(-1);
      }
      std::unique_ptr<std::uint8_t[]> buf2{new std::uint8_t[bufsize]};
      ip.GetData(buf2.get(), bufsize);
      ip.Close();
      if (memcmp(buf1.get(), buf2.get(), bufsize) != 0) {
         std::cerr << "Data in output file does not match data in input.\n";
         exit(-1);
      }

   } catch (std::exception const& e) {
      std::cerr << "Exception thrown in libics: " << e.what() << '\n';
      exit(-1);
   }
}