Commit fbf0ab021de1c810bc1ce4398e692587a8f28144

Authored by David Mayerich
1 parent d32a1854

added support for the new image interface

Showing 3 changed files with 24 additions and 9 deletions   Show diff stats
@@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
6 #include "../envi/bip.h" 6 #include "../envi/bip.h"
7 #include "../envi/bil.h" 7 #include "../envi/bil.h"
8 #include <iostream> 8 #include <iostream>
9 -#include "../CImg/CImg.h" 9 +//#include "../image/CImg.h"
10 10
11 namespace stim{ 11 namespace stim{
12 12
1 #ifndef STIM_IMAGE_H 1 #ifndef STIM_IMAGE_H
2 #define STIM_IMAGE_H 2 #define STIM_IMAGE_H
3 3
  4 +#include "CImg.h"
  5 +
4 #include <iostream> 6 #include <iostream>
5 //This static class provides the STIM interface for loading images 7 //This static class provides the STIM interface for loading images
6 // Use this interface for all image management - that way the actual library can be changed without problems 8 // Use this interface for all image management - that way the actual library can be changed without problems
@@ -10,7 +12,7 @@ @@ -10,7 +12,7 @@
10 template <class T> 12 template <class T>
11 class image{ 13 class image{
12 14
13 - CImg<T> data; 15 + cimg_library::CImg<T> data;
14 16
15 public: 17 public:
16 18
@@ -25,8 +27,18 @@ public: @@ -25,8 +27,18 @@ public:
25 } 27 }
26 28
27 //create an image from an interlaced buffer 29 //create an image from an interlaced buffer
28 - void create_interlaced(T* buffer, unsigned int channels = 1){ 30 + void set_interleaved(T* buffer, unsigned int width, unsigned int height, unsigned int channels = 1){
  31 +
  32 + unsigned char* non_interleaved = (unsigned char*)malloc(width * height * 3);
  33 + unsigned int S = width * height;
  34 +
  35 + for(unsigned int i = 0; i < S; i++){
  36 + for(unsigned int c = 0; c < channels; c++){
  37 + non_interleaved[i + c * S] = buffer[i * channels + c];
  38 + }
  39 + }
29 40
  41 + data = cimg_library::CImg<unsigned char>(non_interleaved, width, height, 1, channels);
30 42
31 } 43 }
32 44
visualization/colormap.h
@@ -7,7 +7,7 @@ @@ -7,7 +7,7 @@
7 7
8 //saving an image to a file uses the CImg library 8 //saving an image to a file uses the CImg library
9 //this currently throws a lot of "unreachable" warnings (as of GCC 4.8.2, nvcc 6.5.12) 9 //this currently throws a lot of "unreachable" warnings (as of GCC 4.8.2, nvcc 6.5.12)
10 -#include "../CImg/CImg.h" 10 +#include "../image/image.h"
11 11
12 12
13 #define BREWER_CTRL_PTS 11 13 #define BREWER_CTRL_PTS 11
@@ -34,20 +34,23 @@ namespace stim{ @@ -34,20 +34,23 @@ namespace stim{
34 34
35 enum colormapType {cmBrewer, cmGrayscale, cmRainbow}; 35 enum colormapType {cmBrewer, cmGrayscale, cmRainbow};
36 36
37 -static void buffer2image(unsigned char* buffer, std::string filename, unsigned int x_size, unsigned int y_size) 37 +static void buffer2image(unsigned char* buffer, std::string filename, unsigned int width, unsigned int height)
38 { 38 {
39 - unsigned char* non_interleaved = (unsigned char*)malloc(x_size * y_size * 3); 39 + /*unsigned char* non_interleaved = (unsigned char*)malloc(x_size * y_size * 3);
40 unsigned int S = x_size * y_size; 40 unsigned int S = x_size * y_size;
41 41
42 for(unsigned int i = 0; i < S; i++){ 42 for(unsigned int i = 0; i < S; i++){
43 non_interleaved[i + 0 * S] = buffer[i * 3 + 0]; 43 non_interleaved[i + 0 * S] = buffer[i * 3 + 0];
44 non_interleaved[i + 1 * S] = buffer[i * 3 + 1]; 44 non_interleaved[i + 1 * S] = buffer[i * 3 + 1];
45 non_interleaved[i + 2 * S] = buffer[i * 3 + 2]; 45 non_interleaved[i + 2 * S] = buffer[i * 3 + 2];
46 - } 46 + }*/
47 47
48 //create an image object 48 //create an image object
49 - cimg_library::CImg<unsigned char> image(non_interleaved, x_size, y_size, 1, 3);  
50 - image.save(filename.c_str()); 49 + //cimg_library::CImg<unsigned char> image(non_interleaved, x_size, y_size, 1, 3);
  50 + //image.save(filename.c_str());
  51 + image<unsigned char> I;
  52 + I.set_interleaved(buffer, width, height, 3);
  53 + I.save(filename);
51 } 54 }
52 55
53 #ifdef __CUDACC__ 56 #ifdef __CUDACC__