From be1064b112ce9ff916dee996c8ef426f0f78d6b3 Mon Sep 17 00:00:00 2001 From: David Date: Wed, 18 Jan 2017 18:14:29 -0600 Subject: [PATCH] fixed cropping errors in stim::bil and stim::bsq --- stim/envi/bil.h | 12 ++++++------ stim/envi/bsq.h | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/stim/envi/bil.h b/stim/envi/bil.h index fe194c1..e4d3efe 100644 --- a/stim/envi/bil.h +++ b/stim/envi/bil.h @@ -1214,9 +1214,9 @@ public: bool PROGRESS = false){ //calculate the new image parameters - unsigned long long samples = x1 - x0; - unsigned long long lines = y1 - y0; - unsigned long long bands = b1 - b0; + unsigned long long samples = x1 - x0 + 1; + unsigned long long lines = y1 - y0 + 1; + unsigned long long bands = b1 - b0 + 1; //calculate the size of a line unsigned long long L = samples * sizeof(T); @@ -1232,19 +1232,19 @@ public: unsigned long long jumpb = (X() - samples) * sizeof(T); //distance needed to jump from the previous line of the last band to the next line of the first band - unsigned long long longjump = ((Z() - b1) * X() + b0 * X()) * sizeof(T); + unsigned long long longjump = ((Z() - bands) * X()) * sizeof(T); //set the start position for the cropped region file.seekg((y0 * X() * Z() + b0 * X() + x0) * sizeof(T), std::ios::beg); for (unsigned long long x = 0; x < lines; x++) { - for (unsigned long long z = b0; z < b1; z++) + for (unsigned long long z = b0; z <= b1; z++) { file.read((char *)(temp + z * samples), sizeof(T) * samples); file.seekg(jumpb, std::ios::cur); //go to the next band - if(PROGRESS) progress = (double)(x * Z() + z+1) / (lines * Z()) * 100; + if(PROGRESS) progress = (double)(x * (b1 - b0 + 1) + z + 1) / (lines * (b1 - b0 + 1)) * 100; } //write slice data into target file diff --git a/stim/envi/bsq.h b/stim/envi/bsq.h index f3becca..dc6a814 100644 --- a/stim/envi/bsq.h +++ b/stim/envi/bsq.h @@ -1198,9 +1198,9 @@ public: bool PROGRESS = false){ //calculate the new number of samples, lines, and bands - unsigned long long samples = x1 - x0; - unsigned long long lines = y1 - y0; - unsigned long long bands = b1 - b0; + unsigned long long samples = x1 - x0 + 1; + unsigned long long lines = y1 - y0 + 1; + unsigned long long bands = b1 - b0 + 1; //calculate the size of a single band unsigned long long L = samples * lines * sizeof(T); @@ -1221,7 +1221,7 @@ public: file.seekg( (b0 * X() * Y() + y0 * X() + x0) * sizeof(T), std::ios::beg); //for each band - for (unsigned long long z = b0; z < b1; z++) + for (unsigned long long z = b0; z <= b1; z++) { //std::cout<(temp), L); //write slice data into target file file.seekg(jumpb, std::ios::cur); -- libgit2 0.21.4