Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

image processing of tiff images

17 views
Skip to first unread message

Madan S Ankapura

unread,
Jun 16, 2003, 12:52:03 PM6/16/03
to
hi,
I have 16-bit gray scale tiff image .. I want to display it in my MFC
application .. allow users to draw grids on it[grid code written and tested
without image display, works fine].
Problem : I tried using DIB Section from the article "Working with TIFF
images", it displays totally corrupted TIFF image though it displays correct
"colored" TIFF images.

Has anyone worked on TIFF images !! please reply ..
Thank you ..

regards,
micromysore


code:-----------------------------------------------------------------------
-------
In onFileopen function
m_dib->Create(w,h,32);
uint32 dibwidth = m_dib->GetTotalWidth();
unsigned long * dest = (unsigned long *)m_dib->GetBits();
unsigned long * src = (unsigned long*)malloc(w*sizeof(unsigned long));
void * ptr_src = src;
for (int row = 0; row < h; row++){
int readlen=TIFFReadScanline(tiff,src,h-row,0);
for(int i=0;i<w;i++) src[i]=(src[i]/255)<<16 | (src[i]/255)<<8 |
(src[i]/255);
void * ptr_dest = dest + row * w;
for (int col = 0; col < w; col++)
{
void *ptr_src=src;
void *ptr_dest=dest+row*w;
memcpy(ptr_dest,ptr_src,w*sizeof(int));
}
----------------------------------------------------------------------------
--
DibSection part of code

code:-----------------------------------------------------------------------
-------
class DIBSection
{
void InitObject(void);
protected:
HBITMAP m_hbmp;
HBITMAP m_hbmOld;
void* m_pBits;
CSize m_size;
CDC* m_pdc;
int m_total_width;
BITMAPINFOHEADER m_bih;
public:
DIBSection() ;
virtual ~DIBSection() ;

void Close(void);

// Create a DIBSection
void Create(int cx, int cy, int nbits ) ;

// Draw method
void Draw(CDC* pdcDest, int x, int y) ;

// Set the palette
void SetPalette(CPalette* pPal) ;

CDC* GetDC() {return m_pdc;}
HBITMAP GetHandle() {return m_hbmp;}

unsigned long Width(void)const{ return m_size.cx;}
unsigned long Height(void)const{ return m_size.cy;}
unsigned long GetTotalWidth(void)const{ return m_total_width;}
void * GetBits(void){ return m_pBits;}
BITMAPINFOHEADER& GetBIH(void){ return m_bih;}
};

Regards,
Madan S Ankapura


Ron Natalie

unread,
Jun 16, 2003, 12:58:02 PM6/16/03
to

"Madan S Ankapura" <madana...@spendloveresearch.org> wrote in message news:#xqoGbCN...@tk2msftngp13.phx.gbl...

> hi,
> I have 16-bit gray scale tiff image .. I want to display it in my MFC
> application .. allow users to draw grids on it[grid code written and tested
> without image display, works fine].
> Problem : I tried using DIB Section from the article "Working with TIFF
> images", it displays totally corrupted TIFF image though it displays correct

Nothing in GDI or GDI+ is prepared to deal with more than 8 bits per band. Your
best bet with a 16 bit image is to read it with the www.libtiff.org library and munch
it down to 8 bits yourself.


Madan S Ankapura

unread,
Jun 16, 2003, 1:53:15 PM6/16/03
to
Well i edited the code for hadling 16 bit data ...
m_dib->Create(w,h,24);//was 32

uint32 dibwidth = m_dib->GetTotalWidth();
BYTE* dest = (BYTE *)m_dib->GetBits();
unsigned long* src = (unsigned long*)malloc(w*sizeof(unsigned long));
BYTE* src1 = (BYTE*)malloc(w*sizeof(BYTE));

void * ptr_src = src;
for (int row = 0; row < h; row++){
int readlen=TIFFReadScanline(tiff,src,h-row,0);
//for(int i=0;i<w;i++) src[i]=(src[i]/255)<<16 | (src[i]/255)<<8 |

(src[i]/255);
for(int i=0;i<w;i++)
src1[i]=(BYTE)(((float)src[i]/(float)(1<<16))*(1<<8));

void * ptr_dest = dest + row * w;

//memcpy(ptr_dest,ptr_src,w*sizeof(int));


for (int col = 0; col < w; col++)
{

void *ptr_src=src1;
void *ptr_dest=dest+row*w;
memcpy(ptr_dest,ptr_src,w*sizeof(BYTE));
}

But it wont work .. it is displaying the image is in very small are .. and i
see 3 images :-( ..


Lucas Galfaso

unread,
Jun 16, 2003, 3:27:57 PM6/16/03
to
I would recommend you
http://freeimage.sourceforge.net/
but I never try it in 16 bit.

Lucas/

"Madan S Ankapura" <madana...@spendloveresearch.org> wrote in message

news:%23xqoGbC...@tk2msftngp13.phx.gbl...

0 new messages