2006.03.16 16:53 "[Tiff] libtiff query", by jan.n

Hello,

i was using ifl library earlier to work on the tiff images, and now i need to do the same code using libtiff, any help on the code would be greatly appritiated,

the code which needs conversion is..

BoundingBox * CShakeCropUtilDlg::calcBoundsTIF(CString basename, int frame)

{
BoundingBox *ret = new BoundingBox();
ret->frame = frame;
char fullname[300];
char fullnamePad[300];
sprintf(fullname,"%s.%d.tif",basename,frame);
bool padded = false;
iflStatus sts;
iflFile* file = iflFile::open(fullname, O_RDONLY, &sts);
if (sts != iflOKAY) {
sprintf(fullnamePad,"%s.%s.tif",basename,pad(frame).GetBuffer(20));
file = iflFile::open(fullnamePad, O_RDONLY, &sts);
padded = true;
if (sts != iflOKAY) {
char err[200];
sprintf(err,"Can't load %s OR %s",fullname,fullnamePad);
AfxMessageBox(err,MB_OK | MB_ICONEXCLAMATION );
return NULL;
}
}
// read the entire image (just the first plane in z if image has depth)
// into a buffer of unsiged chars
iflSize dims;
file->getDimensions(dims);
//char err[200];
//sprintf(err,"%s size %d %d",fullname,dims.x,dims.y);
//AfxMessageBox(err,MB_OK | MB_ICONEXCLAMATION );
unsigned char* data = new unsigned char[dims.x*dims.y*dims.c];
iflConfig cfg(iflUChar, iflInterleaved);
sts = file->getTile(0, 0, 0, dims.x, dims.y, 1, data, &cfg);
if (sts != iflOKAY) {/*handle error */}

bool isBlack = true;
int minX = dims.x + 1;
int maxX = -1;
int minY = dims.y + 1;
int maxY = -1;
int x,y,c;
int i = 0;
for(y = (dims.y - 1); y >= 0; y--) {
for(x = 0; x < dims.x; x++ ) {
for( c = 0; c < dims.c; c++) {
if (data[i] != 0 ) {
isBlack = false;
if (x < minX ) minX = x;
if (x > maxX ) maxX = x;
if (y < minY ) minY = y;
if (y > maxY ) maxY = y;
}
i++;
}
}
}

delete [] data;
// close the file
file->close();
if ( minX == 0 )
ret->left = minX;
else
ret->left = minX - 1;
if ( maxX == dims.x )
ret->right = maxX;
else
ret->right = maxX + 1;

if ( minY == 0 )
ret->bottom = minY;
else
ret->bottom = minY - 1;
if ( maxY == dims.y )
ret->top = maxY;
else
ret->top = maxY + 1;
// deal with a black frame
if ( isBlack) {
ret->bottom = 0;
ret->left = 0;
ret->top = 1;
ret->right = 1;
}
return ret;
}

---------------------------------
Share your photos with the people who matter at Yahoo! Canada Photos