Imagine++
Buffer.h
1 // ===========================================================================
2 // Imagine++ Libraries
3 // Copyright (C) Imagine
4 // For detailed information: http://imagine.enpc.fr/software
5 // ===========================================================================
6 
7 // Buffered/convert read / write
8 
9 #ifndef DOXYGEN_SHOULD_SKIP_THIS
10 
11 namespace Imagine {
12  template <class TI, class TO, int dim> bool readBuffer(Image<TO,dim> &I, std::istream &in) {
13  size_t size = I.totalSize();
14  TI *buffer = new TI[size];
15  in.read((char *)buffer,size*sizeof(TI));
16  for (size_t i=0;i<size;i++) I[i] = TO( buffer[i] );
17  delete [] buffer;
18  return true;
19  }
20 
21  template <class TO, class TI, int dim> bool writeBuffer(const Image<TI,dim> &I, std::ostream &out) {
22  size_t size = I.totalSize();
23  TO *buffer = new TO[size];
24  for (size_t i=0;i<size;i++) buffer[i] = TO( I[i] );
25  out.write((char *)buffer,size*sizeof(TO));
26  delete [] buffer;
27  return true;
28  }
29 }
30 
31 #endif
Imagine++ namespace.
Definition: Array.h:7