2
libtiff를 사용하여 tiff 이미지를로드하고 쓰는 이미지 클래스를 작성하고 있습니다.C++에서 libtiff로 쓰기 이미지에 문제가 발생했습니다. TIFFScanlineSize로 정수 오버플로가 발생했습니다.
TIFF *out = TIFFOpen(filename.c_str(),"w") ;
if (out)
{
uint32 imagelength, imagewidth;
uint8 * buf;
uint32 row, col, n;
uint16 config, nsamples;
imagewidth = dims[0] ;
imagelength = dims[1] ;
config = PLANARCONFIG_CONTIG ;
nsamples = cn ;
TIFFSetField(out, TIFFTAG_IMAGELENGTH, &imagelength);
TIFFSetField(out, TIFFTAG_IMAGEWIDTH, &imagewidth);
TIFFSetField(out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, &nsamples);
TIFFSetField(out, TIFFTAG_COMPRESSION, COMPRESSION_LZW) ;
TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, 8) ;
TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(out, imagewidth*nsamples));
std::cout <<nsamples << std::endl ;
buf = new uint8 [imagewidth*nsamples] ;
for (row = 0; row < imagelength; row++){
for(col=0; col < imagewidth; col++){
for(n = 0 ; n < nsamples ; ++n)
{
Vec<T,cn>* temp = image_data[imagewidth*row+col] ;
buf[col*nsamples+n] = static_cast<uint8> ((*temp)[n]) ;
}
}
if (TIFFWriteScanline(out, buf, row) != 1)
{
std::cout << "Unable to write a row." <<std::endl ;
break ;
}
}
_TIFFfree(buf);
TIFFClose(out);
} ...
및 오류 메시지는 다음과 같습니다 : 그러나, 나는이 오류가 계속이를 사용하는 것은 매우 어렵습니다, 내 코드는
:test_write.tiff: Integer overflow in TIFFScanlineSize.
test_write.tiff: Integer overflow in TIFFScanlineSize.
내 호출 코드는 다음과 같다
Image<unsigned char,3> testimg ; //uint8 is unsigned char
testimg.read_image("test.tiff") ;
testimg.write_image("test_write.tiff") ;
필자는 test_write.tiff를 쓸 수는 있지만 이미지 브라우저를 사용하여 열 수는 없으며 파일 크기가 이전과 동일하지 않습니다.
덕분에