diff --git a/stim/image/image.h b/stim/image/image.h index 4a324b2..750aedb 100644 --- a/stim/image/image.h +++ b/stim/image/image.h @@ -95,25 +95,26 @@ public: image(){ init(); } //initialize all variables to zero, don't allocate any memory /// Constructor with a filename - loads the specified file - image(std::string filename) : image(){ //constructor initialize the image with an image file + image(std::string filename){ //constructor initialize the image with an image file + init(); load(filename); } /// Create a new image from scratch given a number of samples and channels - image(size_t x, size_t y = 1, size_t c = 1) : image(){ + image(size_t x, size_t y = 1, size_t c = 1){ init(); allocate(x, y, c); } /// Create a new image with the data given in 'data' - image(T* data, size_t x, size_t y, size_t c = 1) : image(){ + image(T* data, size_t x, size_t y, size_t c = 1){ init(); allocate(x, y, c); memcpy(img, data, bytes()); } /// Copy constructor - duplicates an image object - image(const stim::image& I) : image(){ + image(const stim::image& I){ init(); allocate(I.X(), I.Y(), I.C()); memcpy(img, I.img, bytes()); @@ -358,30 +359,19 @@ public: } ///crops the image from x1 to x0 and y1 to y0 and returns a new (smaller) image. - ///Untested image crop(int x0, int x1, int y0, int y1) { image ret(x1-x0, y1-y0, C()); int newWidth = x1-x0; int destidx, srcidx; + ///for each row, cut what amount of data from the original and put it into the new copy. for(int i = 0; i < (y1-y0); i++) { destidx = i*newWidth*C(); ///destination index one per each row srcidx = ((i+(y0))*X()+x0)*C(); ///source index, one per each row. -// ret.set_interleaved_rgb(img[srcidx], newWidth, y1-y0, C()); memcpy(&ret.img[destidx], &img[srcidx], sizeof(T)*newWidth*C()); } - -// for(int i = 0; i < (x1 -x0); i++) -// { -// for(int j = 0; j < (y1 - y0); j++) -// { -// destidx = j*newWidth*C() + i; -// srcidx = ((i+(y0))*X() +x0)*C() + i; -// ret.img[destidx] = img[srcidx]; -// } -// } return ret; } -- libgit2 0.21.4