Skip to content

Commit 8955410

Browse files
author
Erika
committed
fixed issues with saveTiff function
1 parent 6a3ea22 commit 8955410

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

depthmap/depthmap.cpp

+20-22
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,7 @@ bool Depthmap::loadTiff(const char *tiff, vector<float> &values, uint32_t &w, ui
223223

224224
uint16_t samplesPerPixel = 1;
225225
TIFFGetField(inTiff, TIFFTAG_SAMPLESPERPIXEL, &samplesPerPixel);
226-
if(samplesPerPixel !=
227-
1) {
226+
if(samplesPerPixel !=1) {
228227
cerr << "Not a depthmap, expecting just 1 channel" << endl;
229228
TIFFClose(inTiff);
230229
return false;
@@ -425,7 +424,6 @@ bool Depthmap::loadMask(const char *tifPath){
425424
return false;
426425
}
427426

428-
429427
return true;
430428

431429
}
@@ -471,8 +469,8 @@ void Depthmap::saveTiff(const char *mask_path, vector<float> &values, uint32_t &
471469
return;
472470
}
473471

474-
TIFFSetField(maskTiff, TIFFTAG_IMAGEWIDTH, &w);
475-
TIFFSetField(maskTiff, TIFFTAG_IMAGELENGTH, &h);
472+
TIFFSetField(maskTiff, TIFFTAG_IMAGEWIDTH, w);
473+
TIFFSetField(maskTiff, TIFFTAG_IMAGELENGTH, h);
476474
TIFFSetField(maskTiff, TIFFTAG_SAMPLESPERPIXEL, 1);
477475

478476
if (bitsPerSample == 32) {
@@ -513,31 +511,31 @@ void Depthmap::saveTiff(const char *mask_path, vector<float> &values, uint32_t &
513511
if (bitsPerSample == 1) {
514512

515513
unsigned char * scanline= new unsigned char [scanLineSize];
516-
memset(scanline, 0, scanLineSize);
517514

518-
for (uint32_t row = 0; row < h; ++row) {
519-
// write the current strip
520-
for (uint32_t col = 0; col < w; ++col) {
521-
uint32_t bytePos = col >> 3;
522-
uint32_t bitPos = 7 - (col & 7);
523-
uint32_t dstIndex = row * w + col;
515+
memset(scanline, 0, scanLineSize);
516+
// write the current strip
517+
for (uint32_t col = 0; col < w; ++col) {
518+
uint32_t bytePos = col >> 3;
519+
uint32_t bitPos = 7 - (col & 7);
520+
uint32_t dstIndex = y * w + col;
524521

525-
//values[dstIndex] = (scanline[bytePos] & (1 << bitPos)) != 0;
526-
if(values[dstIndex]){
527-
scanline[bytePos] |= (1 << bitPos);
528-
}
529-
}
530-
if (TIFFWriteScanline(maskTiff, scanline, y, 0) < 0) {
531-
cerr << "Error writing strip " << row << endl;
532-
TIFFClose(maskTiff);
533-
return;
522+
//values[dstIndex] = (scanline[bytePos] & (1 << bitPos)) != 0;
523+
if(values[dstIndex] != 0.0f){
524+
scanline[bytePos] |= (1 << bitPos);
534525
}
535526
}
527+
if (TIFFWriteScanline(maskTiff, scanline, y, 0) < 0) {
528+
cerr << "Error writing strip " << y << endl;
529+
TIFFClose(maskTiff);
530+
return;
531+
}
532+
536533
delete[] scanline;
537534
}
538-
TIFFClose(maskTiff);
535+
539536

540537
}
538+
TIFFClose(maskTiff);
541539
}
542540

543541

0 commit comments

Comments
 (0)