Commit fba6e7e3a1930b22fa6c17acb64eb264131c1612
1 parent
e9a1b974
fixed image.h bug with constructors not working in windows
Showing
1 changed file
with
6 additions
and
16 deletions
Show diff stats
stim/image/image.h
@@ -95,25 +95,26 @@ public: | @@ -95,25 +95,26 @@ public: | ||
95 | image(){ init(); } //initialize all variables to zero, don't allocate any memory | 95 | image(){ init(); } //initialize all variables to zero, don't allocate any memory |
96 | 96 | ||
97 | /// Constructor with a filename - loads the specified file | 97 | /// Constructor with a filename - loads the specified file |
98 | - image(std::string filename) : image(){ //constructor initialize the image with an image file | 98 | + image(std::string filename){ //constructor initialize the image with an image file |
99 | + init(); | ||
99 | load(filename); | 100 | load(filename); |
100 | } | 101 | } |
101 | 102 | ||
102 | /// Create a new image from scratch given a number of samples and channels | 103 | /// Create a new image from scratch given a number of samples and channels |
103 | - image(size_t x, size_t y = 1, size_t c = 1) : image(){ | 104 | + image(size_t x, size_t y = 1, size_t c = 1){ |
104 | init(); | 105 | init(); |
105 | allocate(x, y, c); | 106 | allocate(x, y, c); |
106 | } | 107 | } |
107 | 108 | ||
108 | /// Create a new image with the data given in 'data' | 109 | /// Create a new image with the data given in 'data' |
109 | - image(T* data, size_t x, size_t y, size_t c = 1) : image(){ | 110 | + image(T* data, size_t x, size_t y, size_t c = 1){ |
110 | init(); | 111 | init(); |
111 | allocate(x, y, c); | 112 | allocate(x, y, c); |
112 | memcpy(img, data, bytes()); | 113 | memcpy(img, data, bytes()); |
113 | } | 114 | } |
114 | 115 | ||
115 | /// Copy constructor - duplicates an image object | 116 | /// Copy constructor - duplicates an image object |
116 | - image(const stim::image<T>& I) : image(){ | 117 | + image(const stim::image<T>& I){ |
117 | init(); | 118 | init(); |
118 | allocate(I.X(), I.Y(), I.C()); | 119 | allocate(I.X(), I.Y(), I.C()); |
119 | memcpy(img, I.img, bytes()); | 120 | memcpy(img, I.img, bytes()); |
@@ -358,30 +359,19 @@ public: | @@ -358,30 +359,19 @@ public: | ||
358 | } | 359 | } |
359 | 360 | ||
360 | ///crops the image from x1 to x0 and y1 to y0 and returns a new (smaller) image. | 361 | ///crops the image from x1 to x0 and y1 to y0 and returns a new (smaller) image. |
361 | - ///Untested | ||
362 | image<T> crop(int x0, int x1, int y0, int y1) | 362 | image<T> crop(int x0, int x1, int y0, int y1) |
363 | { | 363 | { |
364 | 364 | ||
365 | image<T> ret(x1-x0, y1-y0, C()); | 365 | image<T> ret(x1-x0, y1-y0, C()); |
366 | int newWidth = x1-x0; | 366 | int newWidth = x1-x0; |
367 | int destidx, srcidx; | 367 | int destidx, srcidx; |
368 | + ///for each row, cut what amount of data from the original and put it into the new copy. | ||
368 | for(int i = 0; i < (y1-y0); i++) | 369 | for(int i = 0; i < (y1-y0); i++) |
369 | { | 370 | { |
370 | destidx = i*newWidth*C(); ///destination index one per each row | 371 | destidx = i*newWidth*C(); ///destination index one per each row |
371 | srcidx = ((i+(y0))*X()+x0)*C(); ///source index, one per each row. | 372 | srcidx = ((i+(y0))*X()+x0)*C(); ///source index, one per each row. |
372 | -// ret.set_interleaved_rgb(img[srcidx], newWidth, y1-y0, C()); | ||
373 | memcpy(&ret.img[destidx], &img[srcidx], sizeof(T)*newWidth*C()); | 373 | memcpy(&ret.img[destidx], &img[srcidx], sizeof(T)*newWidth*C()); |
374 | } | 374 | } |
375 | - | ||
376 | -// for(int i = 0; i < (x1 -x0); i++) | ||
377 | -// { | ||
378 | -// for(int j = 0; j < (y1 - y0); j++) | ||
379 | -// { | ||
380 | -// destidx = j*newWidth*C() + i; | ||
381 | -// srcidx = ((i+(y0))*X() +x0)*C() + i; | ||
382 | -// ret.img[destidx] = img[srcidx]; | ||
383 | -// } | ||
384 | -// } | ||
385 | return ret; | 375 | return ret; |
386 | } | 376 | } |
387 | 377 |