Commit 7b3948ab3d5cfb28360a41d9d803ac31d71dff54

Authored by David Mayerich
1 parent fbf0ab02

added support for the image interface to envi

Showing 2 changed files with 29 additions and 7 deletions   Show diff stats
envi/envi.h
... ... @@ -6,7 +6,7 @@
6 6 #include "../envi/bip.h"
7 7 #include "../envi/bil.h"
8 8 #include <iostream>
9   -//#include "../image/CImg.h"
  9 +#include "../image/image.h"
10 10  
11 11 namespace stim{
12 12  
... ... @@ -641,10 +641,10 @@ public:
641 641 //load mask from maskfile and save it into memory
642 642 bool load_mask(unsigned char * mask, std::string maskname){
643 643 //open the mask file
644   - cimg_library::CImg<unsigned char> mask_image(maskname.c_str());
  644 + stim::image<unsigned char> mask_image(maskname);
645 645 //save mask file into memory
646 646 memcpy(mask, mask_image.data(), mask_image.size());
647   - mask_image.clear();
  647 + //mask_image.clear();
648 648 return true;
649 649 }
650 650  
... ...
image/image.h
... ... @@ -4,6 +4,8 @@
4 4 #include "CImg.h"
5 5  
6 6 #include <iostream>
  7 +
  8 +namespace stim{
7 9 //This static class provides the STIM interface for loading images
8 10 // Use this interface for all image management - that way the actual library can be changed without problems
9 11  
... ... @@ -12,18 +14,27 @@
12 14 template <class T>
13 15 class image{
14 16  
15   - cimg_library::CImg<T> data;
  17 + cimg_library::CImg<T> img;
16 18  
17 19 public:
18 20  
  21 + //default constructor
  22 + image(){
  23 + }
  24 +
  25 + //constructor (load an image file)
  26 + image(std::string filename){
  27 + img.load(filename.c_str());
  28 + }
  29 +
19 30 //Load an image from a file
20 31 void load(std::string filename){
21   - data.load(filename.c_str());
  32 + img.load(filename.c_str());
22 33 }
23 34  
24 35 //save a file
25 36 void save(std::string filename){
26   - data.save(filename.c_str());
  37 + img.save(filename.c_str());
27 38 }
28 39  
29 40 //create an image from an interlaced buffer
... ... @@ -38,8 +49,17 @@ public:
38 49 }
39 50 }
40 51  
41   - data = cimg_library::CImg<unsigned char>(non_interleaved, width, height, 1, channels);
  52 + img = cimg_library::CImg<unsigned char>(non_interleaved, width, height, 1, channels);
  53 + }
  54 +
  55 + //returns a pointer to the first pixel of the image data
  56 + T* data(){
  57 + return img.data();
  58 + }
42 59  
  60 + //returns the size (number of values) of the image
  61 + unsigned long size(){
  62 + return img.size();
43 63 }
44 64  
45 65  
... ... @@ -48,5 +68,7 @@ public:
48 68  
49 69 };
50 70  
  71 +}; //end namespace stim
  72 +
51 73  
52 74 #endif
... ...