// JP opened flex table

Click to See Complete Forum and Search --> : Tiff File Help


celtics
January 6th, 2004, 12:12 AM
(freeware code)MFC/SDI:
NOT SURE WHY THE CODE BELOW DOES NOT WORK FOR MY B&W 16 BIT IMAGE.


void TIFFTestDoc::OnFileOpen()
{
CString file_types = "TIFF Files (*.tiff,*.tif)|*.tif;*.tiff;*.tif;||";
CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY | OFN_EXPLORER,(LPCTSTR)file_types,NULL);
if (dlg.DoModal() == IDOK)
{
m_filename = dlg.GetPathName();
// 1) Open this puppy up
TIFF * tiff = TIFFOpen((char *)(LPCTSTR)m_filename,"r");
if (tiff)
{
int w=0, h=0;
// 2)
// Get the width and height of the image
TIFFGetField(tiff,TIFFTAG_IMAGEWIDTH, &w);
TIFFGetField(tiff,TIFFTAG_IMAGELENGTH, &h);
if ((w > 0) && (h > 0))
{
// allocate space for the image
uint32 * raster = (uint32*)GlobalAlloc(GMEM_FIXED,
(w * h * sizeof (uint32)));
if (raster)
{
// creating DIBSection object that
//encapsulates DIb functionality
if (m_dib) delete m_dib;
m_dib = new DIBSection;
if (m_dib)
{ m_dib->Create(w,h,32); uint32 dibwidth = m_dib->GetTotalWidth();

// 3)
// copy all the pixel data TO allocated space
if (TIFFReadRGBAImage(tiff, w, h, raster, 0))
{
// 4) // its tempting to copy straight to the DIB, however the
// DIB has an alignment restriction that is not applicable // to tiff files...so they may have different widths unsigned long * dest =
(unsigned long *)m_dib->GetBits(); unsigned long * src = (unsigned long *)raster;
for (int row = 0; row < h; row++){
void * ptr_dest = dest + row * dibwidth; void * ptr_src = src + row * w; memcpy(ptr_dest,ptr_src,w*sizeof(int));
}
SetTitle(m_filename);
UpdateAllViews(NULL);
}
}

// 5)
// free the temporary pixel storage space
GlobalFree(raster);
}
}

// 6)
// notify the TIFF library that we are done with this puppy
TIFFClose(tiff);
}
}
}

micromysore
January 20th, 2004, 04:36 PM
for some reason
TIFFReadRGBAImage(tiff, w, h, raster, 0)) doesnt work with
16 bit gray scale images..
use readline instead !!

//JP added flex table