J
james
there are many resource on the internet. the better way is through google.
www.itk.org is one of them. All your concern are possible. I suppose you are
running at windows platform. and plannig to display. you need to recognize
the format of BMP(orDIB). If you'd like to read JPEG file visit
http://www.jpeg.org .
typedef struct tagRGBQUAD {
BYTE rgbBlue;
BYTE rgbGreen;
BYTE rgbRed;
BYTE rgbReserved;
} RGBQUAD;
typedef RGBQUAD* LPRGBQUAD;
typedef struct tagBITMAPINFOHEADER{
DWORD biSize;
LONG biWidth;
LONG biHeight;
WORD biPlanes;
WORD biBitCount;
DWORD biCompression;
DWORD biSizeImage;
LONG biXPelsPerMeter;
LONG biYPelsPerMeter;
DWORD biClrUsed;
DWORD biClrImportant;
} BITMAPINFOHEADER, *LPBITMAPINFOHEADER, *PBITMAPINFOHEADER;
typedef struct tagBITMAPINFO {
BITMAPINFOHEADER bmiHeader;
RGBQUAD bmiColors[1];
} BITMAPINFO, *LPBITMAPINFO, *PBITMAPINFO;
typedef struct tagBITMAPFILEHEADER {
WORD bfType;
DWORD bfSize;
WORD bfReserved1;
WORD bfReserved2;
DWORD bfOffBits;
} BITMAPFILEHEADER, *LPBITMAPFILEHEADER, *PBITMAPFILEHEADER;
//source code for read 8 bit image
BOOL CDib::Load(LPCSTR lpszDibFile)
{
//openfile
ifstream tfile(lpszDibFile,ios::binary|ios::nocreate);
if (tfile) //open sucessful
{
//file header
tfile.read((char*)&(m_bmfHeader.bfType),sizeof(m_bmfHeader.bfType));
tfile.read((char*)&(m_bmfHeader.bfSize),sizeof(m_bmfHeader.bfSize));
tfile.read((char*)&(m_bmfHeader.bfReserved1),sizeof(m_bmfHeader.bfReserved1)
);
tfile.read((char*)&(m_bmfHeader.bfReserved2),sizeof(m_bmfHeader.bfReserved2)
);
tfile.read((char*)&(m_bmfHeader.bfOffBits),sizeof(m_bmfHeader.bfOffBits));
//bitmap info header
tfile.read((char*)&(m_bmiHeader.biSize),sizeof(m_bmiHeader.biSize));
tfile.read((char*)&(m_bmiHeader.biWidth),sizeof(m_bmiHeader.biWidth));
tfile.read((char*)&(m_bmiHeader.biHeight),sizeof(m_bmiHeader.biHeight));
tfile.read((char*)&(m_bmiHeader.biPlanes),sizeof(m_bmiHeader.biPlanes));
tfile.read((char*)&(m_bmiHeader.biBitCount),sizeof(m_bmiHeader.biBitCount));
tfile.read((char*)&(m_bmiHeader.biCompression),sizeof(m_bmiHeader.biCompress
ion));
tfile.read((char*)&(m_bmiHeader.biSizeImage),sizeof(m_bmiHeader.biSizeImage)
);
tfile.read((char*)&(m_bmiHeader.biXPelsPerMeter),sizeof(m_bmiHeader.biXPelsP
erMeter));
tfile.read((char*)&(m_bmiHeader.biYPelsPerMeter),sizeof(m_bmiHeader.biYPelsP
erMeter));
tfile.read((char*)&(m_bmiHeader.biClrUsed),sizeof(m_bmiHeader.biClrUsed));
tfile.read((char*)&(m_bmiHeader.biClrImportant),sizeof(m_bmiHeader.biClrImpo
rtant));
//RGB
RGBQUAD* rgb;
m_Palette.SetSize(256);
long i;
for (i=0;i <m_Palette.GetSize();i++)
{
rgb=0;
rgb=new RGBQUAD;
tfile.read((char*)&(rgb->rgbBlue),sizeof(rgb->rgbBlue));
tfile.read((char*)&(rgb->rgbGreen),sizeof(rgb->rgbGreen));
tfile.read((char*)&(rgb->rgbRed),sizeof(rgb->rgbRed));
tfile.read((char*)&(rgb->rgbReserved),sizeof(rgb->rgbReserved));
m_Palette.SetAtGrow(i,(CObject*)rgb);
}
//image data
long nSize=m_bmiHeader.biWidth*m_bmiHeader.biHeight;
m_pData=(BYTE*)malloc(nSize*sizeof(BYTE));
tfile.read((char*)m_pData,nSize);
}
tfile.close();
return 0;
}
// get pixel
RGBQUAD* CDib::GetPixel(LONG x, LONG y)
{
BYTE index=0;
RGBQUAD* rgb;
int nOffset=(m_bmiHeader.biHeight-y-1)*m_bmiHeader.biWidth+x;
index=*(m_pData+nOffset);
rgb=(RGBQUAD*)m_Palette.GetAt(index);
return rgb;
}
----- Original Message -----
From: "Joe" <[email protected]>
Newsgroups: comp.lang.c++
Sent: Wednesday, February 04, 2004 7:51 AM
Subject: Newbie read image help
www.itk.org is one of them. All your concern are possible. I suppose you are
running at windows platform. and plannig to display. you need to recognize
the format of BMP(orDIB). If you'd like to read JPEG file visit
http://www.jpeg.org .
typedef struct tagRGBQUAD {
BYTE rgbBlue;
BYTE rgbGreen;
BYTE rgbRed;
BYTE rgbReserved;
} RGBQUAD;
typedef RGBQUAD* LPRGBQUAD;
typedef struct tagBITMAPINFOHEADER{
DWORD biSize;
LONG biWidth;
LONG biHeight;
WORD biPlanes;
WORD biBitCount;
DWORD biCompression;
DWORD biSizeImage;
LONG biXPelsPerMeter;
LONG biYPelsPerMeter;
DWORD biClrUsed;
DWORD biClrImportant;
} BITMAPINFOHEADER, *LPBITMAPINFOHEADER, *PBITMAPINFOHEADER;
typedef struct tagBITMAPINFO {
BITMAPINFOHEADER bmiHeader;
RGBQUAD bmiColors[1];
} BITMAPINFO, *LPBITMAPINFO, *PBITMAPINFO;
typedef struct tagBITMAPFILEHEADER {
WORD bfType;
DWORD bfSize;
WORD bfReserved1;
WORD bfReserved2;
DWORD bfOffBits;
} BITMAPFILEHEADER, *LPBITMAPFILEHEADER, *PBITMAPFILEHEADER;
//source code for read 8 bit image
BOOL CDib::Load(LPCSTR lpszDibFile)
{
//openfile
ifstream tfile(lpszDibFile,ios::binary|ios::nocreate);
if (tfile) //open sucessful
{
//file header
tfile.read((char*)&(m_bmfHeader.bfType),sizeof(m_bmfHeader.bfType));
tfile.read((char*)&(m_bmfHeader.bfSize),sizeof(m_bmfHeader.bfSize));
tfile.read((char*)&(m_bmfHeader.bfReserved1),sizeof(m_bmfHeader.bfReserved1)
);
tfile.read((char*)&(m_bmfHeader.bfReserved2),sizeof(m_bmfHeader.bfReserved2)
);
tfile.read((char*)&(m_bmfHeader.bfOffBits),sizeof(m_bmfHeader.bfOffBits));
//bitmap info header
tfile.read((char*)&(m_bmiHeader.biSize),sizeof(m_bmiHeader.biSize));
tfile.read((char*)&(m_bmiHeader.biWidth),sizeof(m_bmiHeader.biWidth));
tfile.read((char*)&(m_bmiHeader.biHeight),sizeof(m_bmiHeader.biHeight));
tfile.read((char*)&(m_bmiHeader.biPlanes),sizeof(m_bmiHeader.biPlanes));
tfile.read((char*)&(m_bmiHeader.biBitCount),sizeof(m_bmiHeader.biBitCount));
tfile.read((char*)&(m_bmiHeader.biCompression),sizeof(m_bmiHeader.biCompress
ion));
tfile.read((char*)&(m_bmiHeader.biSizeImage),sizeof(m_bmiHeader.biSizeImage)
);
tfile.read((char*)&(m_bmiHeader.biXPelsPerMeter),sizeof(m_bmiHeader.biXPelsP
erMeter));
tfile.read((char*)&(m_bmiHeader.biYPelsPerMeter),sizeof(m_bmiHeader.biYPelsP
erMeter));
tfile.read((char*)&(m_bmiHeader.biClrUsed),sizeof(m_bmiHeader.biClrUsed));
tfile.read((char*)&(m_bmiHeader.biClrImportant),sizeof(m_bmiHeader.biClrImpo
rtant));
//RGB
RGBQUAD* rgb;
m_Palette.SetSize(256);
long i;
for (i=0;i <m_Palette.GetSize();i++)
{
rgb=0;
rgb=new RGBQUAD;
tfile.read((char*)&(rgb->rgbBlue),sizeof(rgb->rgbBlue));
tfile.read((char*)&(rgb->rgbGreen),sizeof(rgb->rgbGreen));
tfile.read((char*)&(rgb->rgbRed),sizeof(rgb->rgbRed));
tfile.read((char*)&(rgb->rgbReserved),sizeof(rgb->rgbReserved));
m_Palette.SetAtGrow(i,(CObject*)rgb);
}
//image data
long nSize=m_bmiHeader.biWidth*m_bmiHeader.biHeight;
m_pData=(BYTE*)malloc(nSize*sizeof(BYTE));
tfile.read((char*)m_pData,nSize);
}
tfile.close();
return 0;
}
// get pixel
RGBQUAD* CDib::GetPixel(LONG x, LONG y)
{
BYTE index=0;
RGBQUAD* rgb;
int nOffset=(m_bmiHeader.biHeight-y-1)*m_bmiHeader.biWidth+x;
index=*(m_pData+nOffset);
rgb=(RGBQUAD*)m_Palette.GetAt(index);
return rgb;
}
----- Original Message -----
From: "Joe" <[email protected]>
Newsgroups: comp.lang.c++
Sent: Wednesday, February 04, 2004 7:51 AM
Subject: Newbie read image help