Commit be1064b112ce9ff916dee996c8ef426f0f78d6b3

Authored by David Mayerich
1 parent 77281320

fixed cropping errors in stim::bil and stim::bsq

Showing 2 changed files with 11 additions and 11 deletions   Show diff stats
@@ -1214,9 +1214,9 @@ public: @@ -1214,9 +1214,9 @@ public:
1214 bool PROGRESS = false){ 1214 bool PROGRESS = false){
1215 1215
1216 //calculate the new image parameters 1216 //calculate the new image parameters
1217 - unsigned long long samples = x1 - x0;  
1218 - unsigned long long lines = y1 - y0;  
1219 - unsigned long long bands = b1 - b0; 1217 + unsigned long long samples = x1 - x0 + 1;
  1218 + unsigned long long lines = y1 - y0 + 1;
  1219 + unsigned long long bands = b1 - b0 + 1;
1220 1220
1221 //calculate the size of a line 1221 //calculate the size of a line
1222 unsigned long long L = samples * sizeof(T); 1222 unsigned long long L = samples * sizeof(T);
@@ -1232,19 +1232,19 @@ public: @@ -1232,19 +1232,19 @@ public:
1232 unsigned long long jumpb = (X() - samples) * sizeof(T); 1232 unsigned long long jumpb = (X() - samples) * sizeof(T);
1233 1233
1234 //distance needed to jump from the previous line of the last band to the next line of the first band 1234 //distance needed to jump from the previous line of the last band to the next line of the first band
1235 - unsigned long long longjump = ((Z() - b1) * X() + b0 * X()) * sizeof(T); 1235 + unsigned long long longjump = ((Z() - bands) * X()) * sizeof(T);
1236 1236
1237 //set the start position for the cropped region 1237 //set the start position for the cropped region
1238 file.seekg((y0 * X() * Z() + b0 * X() + x0) * sizeof(T), std::ios::beg); 1238 file.seekg((y0 * X() * Z() + b0 * X() + x0) * sizeof(T), std::ios::beg);
1239 1239
1240 for (unsigned long long x = 0; x < lines; x++) 1240 for (unsigned long long x = 0; x < lines; x++)
1241 { 1241 {
1242 - for (unsigned long long z = b0; z < b1; z++) 1242 + for (unsigned long long z = b0; z <= b1; z++)
1243 { 1243 {
1244 file.read((char *)(temp + z * samples), sizeof(T) * samples); 1244 file.read((char *)(temp + z * samples), sizeof(T) * samples);
1245 file.seekg(jumpb, std::ios::cur); //go to the next band 1245 file.seekg(jumpb, std::ios::cur); //go to the next band
1246 1246
1247 - if(PROGRESS) progress = (double)(x * Z() + z+1) / (lines * Z()) * 100; 1247 + if(PROGRESS) progress = (double)(x * (b1 - b0 + 1) + z + 1) / (lines * (b1 - b0 + 1)) * 100;
1248 } 1248 }
1249 1249
1250 //write slice data into target file 1250 //write slice data into target file
@@ -1198,9 +1198,9 @@ public: @@ -1198,9 +1198,9 @@ public:
1198 bool PROGRESS = false){ 1198 bool PROGRESS = false){
1199 1199
1200 //calculate the new number of samples, lines, and bands 1200 //calculate the new number of samples, lines, and bands
1201 - unsigned long long samples = x1 - x0;  
1202 - unsigned long long lines = y1 - y0;  
1203 - unsigned long long bands = b1 - b0; 1201 + unsigned long long samples = x1 - x0 + 1;
  1202 + unsigned long long lines = y1 - y0 + 1;
  1203 + unsigned long long bands = b1 - b0 + 1;
1204 1204
1205 //calculate the size of a single band 1205 //calculate the size of a single band
1206 unsigned long long L = samples * lines * sizeof(T); 1206 unsigned long long L = samples * lines * sizeof(T);
@@ -1221,7 +1221,7 @@ public: @@ -1221,7 +1221,7 @@ public:
1221 file.seekg( (b0 * X() * Y() + y0 * X() + x0) * sizeof(T), std::ios::beg); 1221 file.seekg( (b0 * X() * Y() + y0 * X() + x0) * sizeof(T), std::ios::beg);
1222 1222
1223 //for each band 1223 //for each band
1224 - for (unsigned long long z = b0; z < b1; z++) 1224 + for (unsigned long long z = b0; z <= b1; z++)
1225 { 1225 {
1226 //std::cout<<z<<std::endl; 1226 //std::cout<<z<<std::endl;
1227 for (unsigned long long y = 0; y < lines; y++) 1227 for (unsigned long long y = 0; y < lines; y++)
@@ -1229,7 +1229,7 @@ public: @@ -1229,7 +1229,7 @@ public:
1229 file.read((char *)(temp + y * samples), sizeof(T) * samples); 1229 file.read((char *)(temp + y * samples), sizeof(T) * samples);
1230 file.seekg(jumpl, std::ios::cur); //go to the next band 1230 file.seekg(jumpl, std::ios::cur); //go to the next band
1231 1231
1232 - if(PROGRESS) progress = (double)((z - b0 + 1) * lines + y + 1) / ((b1 - b0) * lines) * 100; 1232 + if(PROGRESS) progress = (double)((z - b0) * lines + y + 1) / ((b1 - b0 + 1) * lines) * 100;
1233 } 1233 }
1234 out.write(reinterpret_cast<const char*>(temp), L); //write slice data into target file 1234 out.write(reinterpret_cast<const char*>(temp), L); //write slice data into target file
1235 file.seekg(jumpb, std::ios::cur); 1235 file.seekg(jumpb, std::ios::cur);