本文整理汇总了C++中WIDTHBYTES函数的典型用法代码示例。如果您正苦于以下问题:C++ WIDTHBYTES函数的具体用法?C++ WIDTHBYTES怎么用?C++ WIDTHBYTES使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了WIDTHBYTES函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
HDIB CxDib::Create(DWORD dwWidth, DWORD dwHeight, WORD wBitCount)
{
LPBITMAPINFOHEADER lpbi; // pointer to BITMAPINFOHEADER
DWORD dwLen; // size of memory block
if (hDib) free(hDib);
hDib=NULL;
// Make sure bits per pixel is valid
if (wBitCount <= 1) wBitCount = 1;
else if (wBitCount <= 4) wBitCount = 4;
else if (wBitCount <= 8) wBitCount = 8;
else wBitCount = 24;
switch (wBitCount){
case 1:
m_nColors = 2;
break;
case 4:
m_nColors = 16;
break;
case 8:
m_nColors = 256;
break;
default:
m_nColors = 0;
}
m_LineWidth = WIDTHBYTES(wBitCount * dwWidth);
// initialize BITMAPINFOHEADER
m_bi.biSize = sizeof(BITMAPINFOHEADER);
m_bi.biWidth = dwWidth; // fill in width from parameter
m_bi.biHeight = dwHeight; // fill in height from parameter
m_bi.biPlanes = 1; // must be 1
m_bi.biBitCount = wBitCount; // from parameter
m_bi.biCompression = BI_RGB;
m_bi.biSizeImage = m_LineWidth * dwHeight;
m_bi.biXPelsPerMeter = 0;
m_bi.biYPelsPerMeter = 0;
m_bi.biClrUsed = 0;
m_bi.biClrImportant = 0;
// calculate size of memory block required to store the DIB. This
// block should be big enough to hold the BITMAPINFOHEADER, the color
// table, and the bits
dwLen = GetSize();
//hDib = malloc(dwLen); // alloc memory block to store our bitmap
hDib = new (HDIB[dwLen]); //fixes allocation problem under Win2k
if (!hDib) return NULL;
// use our bitmap info structure to fill in first part of
// our DIB with the BITMAPINFOHEADER
lpbi = (LPBITMAPINFOHEADER)(hDib);
*lpbi = m_bi;
return hDib; //return handle to the DIB
}
示例2: printf
bool CImageObject::LoadImageBMP( char *filename )
{
BITMAPFILEHEADER bmFileHeader;
BITMAPINFOHEADER bmInfoHeader;
CFile file;
if (!file.Open(filename, CFile::modeNoTruncate | CFile::modeRead ))
{
printf("No file %s", filename);
return false;
}
file.Read(&bmFileHeader, sizeof(BITMAPFILEHEADER));
file.Read(&bmInfoHeader, sizeof(BITMAPINFOHEADER));
m_ImageWidth = bmInfoHeader.biWidth;
m_ImageHeight = abs(bmInfoHeader.biHeight);
int bytespixel_src = bmInfoHeader.biBitCount/8;
BYTE *PixelFlip = new BYTE[m_ImageHeight * m_ImageWidth * bytespixel_src];
file.Read(PixelFlip, m_ImageHeight * m_ImageWidth * bytespixel_src);
file.Close();
if (m_rgb_pixel != NULL)
delete m_rgb_pixel;
if (m_display_pixel != NULL)
delete m_display_pixel;
int widthbytes_display = WIDTHBYTES(m_ImageWidth,bmInfoHeader.biBitCount);
m_rgb_pixel = new BYTE[m_ImageHeight * m_ImageWidth * 3];
// Loading Flip BMP image
for (int row=0;row<m_ImageHeight;row++)
{
for (int col=0;col<m_ImageWidth;col++)
{
m_rgb_pixel[3 * ((m_ImageHeight - row - 1)*m_ImageWidth+col) ] = PixelFlip[(row*widthbytes_display + col*bytespixel_src) + 0];
m_rgb_pixel[3 * ((m_ImageHeight - row - 1)*m_ImageWidth+col) + 1] = PixelFlip[(row*widthbytes_display + col*bytespixel_src) + 1];
m_rgb_pixel[3 * ((m_ImageHeight - row - 1)*m_ImageWidth+col) + 2] = PixelFlip[(row*widthbytes_display + col*bytespixel_src) + 2];
}
}
//delete temp2;
delete [] PixelFlip;
return true;
// Invalidate(FALSE);
}
示例3: CopyGlyphBitmapToPixelData
//handles copying the image data from the associated bitmap to the 16 bit texture provided
static void CopyGlyphBitmapToPixelData( BITMAPINFO const& bmi, uint8 const* pDibBits,
const LTRect2n& rectDest,
TEXTMETRICW const& textMetric,
uint8* pPixelData, SIZE const& sizeTexture )
{
//pitches of each surface
const int nBitmapPitch = WIDTHBYTES( bmi.bmiHeader.biBitCount, bmi.bmiHeader.biWidth );
const int nPixelDataPitch = WIDTHBYTES( 16, sizeTexture.cx );
//pixel byte widths of the bitmap surface
const int nBitmapPixelWidth = (bmi.bmiHeader.biBitCount + 7) / 8;
//calculate the width
const int nGlyphWidth = rectDest.GetWidth();
//calcualte the height
const int nGlyphHeight = rectDest.GetHeight();
// Copy the glyph pixels to the pixeldata. Leave the rgb of the pixeldata set to white.
// This lets the font antialias with any color background.
for( int y = 0; y < nGlyphHeight; y++ )
{
// Find out where to start this row by offset by y using the passed in bitmap pitch.
// We only need to copy the glyph pixels, so we advance into the bitmap to
// where they start. The source is 24 bpp.
const uint8* pSrcPos = pDibBits + ( y * nBitmapPitch );
// The pixeldata pointer will be pointing to some region in
// the middle of a larger bitmap. So, we use the pixeldatapitch
// passed in to calculate how much to advance per line. We don't want
// to write out any columns to the left or right of the actual glyph.
uint16* pDestPos = ( uint16* )( pPixelData + (( y + rectDest.Top() ) * nPixelDataPitch ) + (rectDest.Left() * 2) );
// Copy this row.
for( int x = 0; x < nGlyphWidth; x++ )
{
// The source is 24 bits. Just take r and use it as the alpha value.
uint32 nVal = MulDiv( pSrcPos[0], 15, 255 );
*pDestPos = ( *pDestPos & 0x0FFF ) | (( nVal & 0x0F ) << 12 );
pDestPos++;
pSrcPos += nBitmapPixelWidth;
}
}
}
示例4: LoadJpegFile
char* LoadJpegFile (char *jpegbuf, char *bmpbuf)
{
DWORD ImgSize;
DWORD JpegBufSize;
int funcret;
LPBITMAPINFOHEADER lpImgData;
//JpegBufSize=size;
lpJpegBuf=jpegbuf;
InitTable();
if((funcret=InitTag())!=FUNC_OK)
{
showerror(funcret);
return NULL;
}
//create new bitmapfileheader and bitmapinfoheader
memset((char *)&bf,0,sizeof(BITMAPFILEHEADER));
memset((char *)&bi,0,sizeof(BITMAPINFOHEADER));
bi.biSize=(DWORD)sizeof(BITMAPINFOHEADER);
bi.biWidth=(LONG)(ImgWidth);
bi.biHeight=(LONG)(ImgHeight);
bi.biPlanes=1;
bi.biBitCount=24;
bi.biClrUsed=0;
bi.biClrImportant=0;
bi.biCompression=BI_RGB;
NumColors=0;
LineBytes=(DWORD)WIDTHBYTES(bi.biWidth*bi.biBitCount);
ImgSize=(DWORD)LineBytes*bi.biHeight;
bf.bfType=0x4d42;
bf.bfSize=/*sizeof(BITMAPFILEHEADER)*/ 14+sizeof(BITMAPINFOHEADER)+NumColors*sizeof(RGBQUAD)+ImgSize;
bf.bfOffBits=(DWORD)(NumColors*sizeof(RGBQUAD)+14/*sizeof(BITMAPFILEHEADER)*/+sizeof(BITMAPINFOHEADER));
lpPtr = (char*)bmpbuf + 54;
if((SampRate_Y_H==0)||(SampRate_Y_V==0))
{
showerror(FUNC_FORMAT_ERROR);
return NULL ;
}
funcret=Decode();
memcpy(bmpbuf, &bf.bfType,sizeof(WORD));
memcpy(bmpbuf+2, ((char*)&bf)+4, 12);
memcpy(bmpbuf+14, (LPSTR)&bi,sizeof(BITMAPINFOHEADER));
if(funcret!=FUNC_OK)
{
showerror(funcret);
return NULL;
}
return lpPtr;
}
示例5: DIBToIconImage
/****************************************************************************
*
* FUNCTION: DIBToIconImage
*
* PURPOSE: Converts a CF_DIB memory block to an icon image
*
* PARAMS: LPICONIMAGE lpii - pointer to icon image data
* LPBYTE lpDIB - a pointer to the CF_DIB block
* BOOL bStretchToFit - TRUE to stretch, FALSE to take
* the upper left corner of the DIB
*
* RETURNS: BOOL - TRUE for success, FALSE for failure
*
* History:
* July '95 - Created
*
\****************************************************************************/
BOOL DIBToIconImage( LPICONIMAGE lpii, LPBYTE lpDIB, BOOL bStretch )
{
LPBYTE lpNewDIB;
// Sanity check
if( lpDIB == NULL )
return FALSE;
// Let the DIB engine convert color depths if need be
lpNewDIB = ConvertDIBFormat( (LPBITMAPINFO)lpDIB, lpii->Width, lpii->Height, lpii->Colors, bStretch );
// Now we have a cool new DIB of the proper size/color depth
// Lets poke it into our data structures and be done with it
// How big is it?
lpii->dwNumBytes = sizeof( BITMAPINFOHEADER ) // Header
+ PaletteSize( (LPSTR)lpNewDIB ) // Palette
+ lpii->Height * BytesPerLine( (LPBITMAPINFOHEADER)lpNewDIB ) // XOR mask
+ lpii->Height * WIDTHBYTES( lpii->Width ); // AND mask
// If there was already an image here, free it
if( lpii->lpBits != NULL )
free( lpii->lpBits );
// Allocate enough room for the new image
if( (lpii->lpBits = malloc( lpii->dwNumBytes )) == NULL )
{
free( lpii );
return FALSE;
}
// Copy the bits
memcpy( lpii->lpBits, lpNewDIB, sizeof( BITMAPINFOHEADER ) + PaletteSize( (LPSTR)lpNewDIB ) );
// Adjust internal pointers/variables for new image
lpii->lpbi = (LPBITMAPINFO)(lpii->lpBits);
lpii->lpbi->bmiHeader.biHeight *= 2;
lpii->lpXOR = FindDIBBits( (LPSTR)(lpii->lpBits) );
memcpy( lpii->lpXOR, FindDIBBits((LPSTR)lpNewDIB), lpii->Height * BytesPerLine( (LPBITMAPINFOHEADER)lpNewDIB ) );
lpii->lpAND = lpii->lpXOR + lpii->Height * BytesPerLine( (LPBITMAPINFOHEADER)lpNewDIB );
memset( lpii->lpAND, 0, lpii->Height * WIDTHBYTES( lpii->Width ) );
// Free the source
free( lpNewDIB );
return TRUE;
}
示例6: AllocRoomForDIB
HANDLE AllocRoomForDIB(BITMAPINFOHEADER bi, HBITMAP hBitmap)
{
DWORD dwLen;
HANDLE hDIB;
HDC hDC;
LPBITMAPINFOHEADER lpbi;
HANDLE hTemp;
/* Figure out the size needed to hold the BITMAPINFO structure
* (which includes the BITMAPINFOHEADER and the color table).
*/
dwLen = bi.biSize + PaletteSize((LPSTR) &bi);
hDIB = GlobalAlloc(GHND,dwLen);
/* Check that DIB handle is valid */
if (!hDIB)
return NULL;
/* Set up the BITMAPINFOHEADER in the newly allocated global memory,
* then call GetDIBits() with lpBits = NULL to have it fill in the
* biSizeImage field for us.
*/
lpbi = (VOID FAR *)GlobalLock(hDIB);
*lpbi = bi;
hDC = GetDC(NULL);
GetDIBits(hDC, hBitmap, 0, (WORD) bi.biHeight,
NULL, (LPBITMAPINFO) lpbi, DIB_RGB_COLORS);
ReleaseDC(NULL, hDC);
/* If the driver did not fill in the biSizeImage field,
* fill it in -- NOTE: this is a bug in the driver!
*/
if (lpbi->biSizeImage == 0)
lpbi->biSizeImage = WIDTHBYTES((DWORD)lpbi->biWidth * lpbi->biBitCount) *
lpbi->biHeight;
/* Get the size of the memory block we need */
dwLen = lpbi->biSize + PaletteSize((LPSTR) &bi) + lpbi->biSizeImage;
/* Unlock the memory block */
GlobalUnlock(hDIB);
/* ReAlloc the buffer big enough to hold all the bits */
if (hTemp = GlobalReAlloc(hDIB,dwLen,0))
return hTemp;
else
{
/* Else free memory block and return failure */
GlobalFree(hDIB);
return NULL;
}
}
示例7: WIDTHBYTES
//在固定位置将点变为红色
void CIconOperate::SetPointColor(int x, int y, DWORD color)
{
if(m_IconData == NULL || m_IconDir == NULL)
return ;
if (x < 0 || x >= m_IconDir->idEntries[0].bwidth || y < 0 || y >= m_IconDir->idEntries[0].bheight )
return ;
int index = (y * WIDTHBYTES(m_IconDir->idEntries[0].bwidth,m_IconDir->idEntries[0].wbitcount) + x*4);
*(DWORD*)(&m_IconData->data[0].icxor[index]) = color ;
}
示例8: ReadJPEGFile
// load jpeg file
BOOL CJpeg::Load(LPCSTR lpstrFileName)
{
UINT uWidth, uHeight, uWidthDW;
// read the jpeg to a packed buffer of RGB bytes
BYTE *lpTmpBuffer = ReadJPEGFile(lpstrFileName, &uWidth, &uHeight);
if (lpTmpBuffer == NULL)
return FALSE;
// do this before DWORD-alignment!!!
// swap red and blue for display
BGRFromRGB(lpTmpBuffer, uWidth, uHeight);
// now DWORD-align for display
BYTE *lpBuffer = MakeDwordAlign(lpTmpBuffer, uWidth, uHeight, &uWidthDW);
FreeBuffer(lpTmpBuffer);
// flip for display
VertFlipBuf(lpBuffer, uWidthDW, uHeight);
BITMAPINFOHEADER bmiHeader;
bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmiHeader.biWidth = uWidth;
bmiHeader.biHeight = uHeight;
bmiHeader.biPlanes = 1;
bmiHeader.biBitCount = 24;
bmiHeader.biCompression = BI_RGB;
bmiHeader.biSizeImage = 0;
bmiHeader.biXPelsPerMeter = 0;
bmiHeader.biYPelsPerMeter = 0;
bmiHeader.biClrUsed = 0;
bmiHeader.biClrImportant = 0;
// Allocate enough memory for the new CF_DIB, and copy bits
DWORD dwHeaderSize = sizeof(BITMAPINFOHEADER);
DWORD dwBitsSize = WIDTHBYTES(uWidth*24) * uHeight;
HDIB hDIB = GlobalAlloc(GHND, dwHeaderSize + dwBitsSize);
if (hDIB == NULL)
return FALSE;
LPBYTE lpDIB = (LPBYTE)GlobalLock(hDIB);
memcpy(lpDIB, (LPBYTE)&bmiHeader, dwHeaderSize);
memcpy(FindDIBBits((LPBYTE)lpDIB), lpBuffer, dwBitsSize);
FreeBuffer(lpBuffer);
if (m_pDib != NULL)
delete m_pDib;
m_pDib = new CDib();
m_pDib->Attach(hDIB);
return TRUE;
}
示例9: CreateBlankNewFormatIcon
/****************************************************************************
*
* FUNCTION: CreateBlankNewFormatIcon
*
* PURPOSE: Creates a blank icon image for a new format
*
* PARAMS: LPICONIMAGE lpii - pointer to icon image data
*
* RETURNS: BOOL - TRUE for success, FALSE for failure
*
* History:
* July '95 - Created
*
\****************************************************************************/
BOOL CreateBlankNewFormatIcon( LPICONIMAGE lpii )
{
DWORD dwFinalSize;
BITMAPINFOHEADER bmih;
// Fill in the bitmap header
ZeroMemory( &bmih, sizeof( BITMAPINFOHEADER ) );
bmih.biSize = sizeof( BITMAPINFOHEADER );
bmih.biBitCount = lpii->Colors;
bmih.biClrUsed = 0;
// How big will the final thing be?
// Well, it'll have a header
dwFinalSize = sizeof( BITMAPINFOHEADER );
// and a color table (even if it's zero length)
dwFinalSize += PaletteSize( (LPSTR)&bmih );
// and XOR bits
dwFinalSize += lpii->Height * WIDTHBYTES( lpii->Width * lpii->Colors );
// and AND bits. That's about it :)
dwFinalSize += lpii->Height * WIDTHBYTES( lpii->Width );
// Allocate some memory for it
lpii->lpBits = malloc( dwFinalSize );
ZeroMemory( lpii->lpBits, dwFinalSize );
lpii->dwNumBytes = dwFinalSize;
lpii->lpbi = (LPBITMAPINFO)(lpii->lpBits);
lpii->lpXOR = (LPSTR)(lpii->lpbi) + sizeof(BITMAPINFOHEADER) + PaletteSize( (LPSTR)&bmih );
lpii->lpAND = lpii->lpXOR + (lpii->Height * WIDTHBYTES( lpii->Width * lpii->Colors ));
// The bitmap header is zeros, fill it out
lpii->lpbi->bmiHeader.biSize = sizeof( BITMAPINFOHEADER );
lpii->lpbi->bmiHeader.biWidth = lpii->Width;
// Don't forget the funky height*2 icon resource thing
lpii->lpbi->bmiHeader.biHeight = lpii->Height * 2;
lpii->lpbi->bmiHeader.biPlanes = 1;
lpii->lpbi->bmiHeader.biBitCount = lpii->Colors;
lpii->lpbi->bmiHeader.biCompression = BI_RGB;
return TRUE;
}
示例10: getStripContig1Bit
/*
* Get a strip-organized image that has
* PlanarConfiguration contiguous if SamplesPerPixel > 1
* or
* SamplesPerPixel == 1
*
* Hacked from the tif_getimage.c file.
*
* This is set up to allow us to just copy the data to the raster
* for 1-bit bitmaps
*/
static int
getStripContig1Bit(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h)
{
TIFF* tif = img->tif;
tileContigRoutine put = img->put.contig;
uint16 orientation;
uint32 row, y, nrow, rowstoread;
uint32 pos;
u_char* buf;
uint32 rowsperstrip;
uint32 imagewidth = img->width;
tsize_t scanline;
int32 fromskew, toskew;
tstrip_t strip;
tsize_t stripsize;
u_char* braster = (u_char*)raster; // byte wide raster
uint32 wb = WIDTHBYTES(w);
int ret = 1;
buf = (u_char*) _TIFFmalloc(TIFFStripSize(tif));
if (buf == 0) {
TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "No space for strip buffer");
return (0);
}
y = setorientation(img, h);
orientation = img->orientation;
toskew = -(int32) (orientation == ORIENTATION_TOPLEFT ? wb+wb : wb-wb);
TIFFGetFieldDefaulted(tif, TIFFTAG_ROWSPERSTRIP, &rowsperstrip);
scanline = TIFFScanlineSize(tif);
fromskew = (w < imagewidth ? imagewidth - w : 0)/8;
for (row = 0; row < h; row += nrow)
{
rowstoread = rowsperstrip - (row + img->row_offset) % rowsperstrip;
nrow = (row + rowstoread > h ? h - row : rowstoread);
strip = TIFFComputeStrip(tif,row+img->row_offset, 0);
stripsize = ((row + img->row_offset)%rowsperstrip + nrow) * scanline;
if (TIFFReadEncodedStrip(tif, strip, buf, stripsize ) < 0
&& img->stoponerr)
{
ret = 0;
break;
}
pos = ((row + img->row_offset) % rowsperstrip) * scanline;
(*put)(img, (uint32*)(braster+y*wb), 0, y, w, nrow, fromskew, toskew, buf + pos);
y += (orientation == ORIENTATION_TOPLEFT ?-(int32) nrow : (int32) nrow);
}
_TIFFfree(buf);
return (ret);
}
示例11: WIDTHBYTES
//
// copies BYTE buffer into DWORD-aligned BYTE buffer
// return addr of new buffer
//
BYTE * CJpeg::MakeDwordAlign(BYTE *dataBuf,
UINT widthPix, // pixels!!
UINT height,
UINT *uiOutWidthBytes) // bytes!!!
{
////////////////////////////////////////////////////////////
// what's going on here? this certainly means trouble
if (dataBuf==NULL)
return NULL;
////////////////////////////////////////////////////////////
// how big is the smallest DWORD-aligned buffer that we can use?
UINT uiWidthBytes;
uiWidthBytes = WIDTHBYTES(widthPix * 24);
DWORD dwNewsize=(DWORD)((DWORD)uiWidthBytes *
(DWORD)height);
BYTE *pNew;
////////////////////////////////////////////////////////////
// alloc and open our new buffer
pNew=(BYTE *)new BYTE[dwNewsize];
if (pNew==NULL) {
return NULL;
}
////////////////////////////////////////////////////////////
// copy row-by-row
UINT uiInWidthBytes = widthPix * 3;
UINT uiCount;
for (uiCount=0;uiCount < height;uiCount++)
{
BYTE * bpInAdd;
BYTE * bpOutAdd;
ULONG lInOff;
ULONG lOutOff;
lInOff=uiInWidthBytes * uiCount;
lOutOff=uiWidthBytes * uiCount;
bpInAdd= dataBuf + lInOff;
bpOutAdd= pNew + lOutOff;
memcpy(bpOutAdd,bpInAdd,uiInWidthBytes);
}
*uiOutWidthBytes=uiWidthBytes;
return pNew;
}
示例12: GetPoints
void GetPoints(int nWidth,int nHeight,BYTE *lpBits,BYTE *lpPoints)
{
int x,y,p;
int nByteWidth = WIDTHBYTES(nWidth*24); //nWidth*3;
//if (nByteWidth%4) nByteWidth+=4-(nByteWidth%4);
for(y=0;y<nHeight;y++)
{
for(x=0;x<nWidth;x++)
{
p=x*3+y*nByteWidth;
lpPoints[x+y*nWidth]=(BYTE)(0.299*(float)lpBits[p+2]+0.587*(float)lpBits[p+1]+0.114*(float)lpBits[p]+0.1);
}
}
}
示例13: WIDTHBYTES
unsigned char * JpegFile::MakeJPG_DWORDAlignedBuf(unsigned char *dataBuf,
JPG_UINT widthPix, // pixels!!
JPG_UINT height,
JPG_UINT *uiOutWidthBytes) // bytes!!!
{
////////////////////////////////////////////////////////////
// what's going on here? this certainly means trouble
if (dataBuf==NULL)
return NULL;
////////////////////////////////////////////////////////////
// how big is the smallest JPG_DWORD-aligned buffer that we can use?
JPG_UINT uiWidthBytes;
uiWidthBytes = WIDTHBYTES(widthPix * 24);
JPG_DWORD dwNewsize=(JPG_DWORD)((JPG_DWORD)uiWidthBytes *
(JPG_DWORD)height);
unsigned char *pNew;
////////////////////////////////////////////////////////////
// alloc and open our new buffer
pNew=(unsigned char *)new unsigned char[dwNewsize];
if (pNew==NULL) {
return NULL;
}
////////////////////////////////////////////////////////////
// copy row-by-row
JPG_UINT uiInWidthBytes = widthPix * 3;
JPG_UINT uiCount;
for (uiCount=0;uiCount < height;uiCount++) {
unsigned char * bpInAdd;
unsigned char * bpOutAdd;
JPG_ULONG lInOff;
JPG_ULONG lOutOff;
lInOff=uiInWidthBytes * uiCount;
lOutOff=uiWidthBytes * uiCount;
bpInAdd= dataBuf + lInOff;
bpOutAdd= pNew + lOutOff;
memcpy(bpOutAdd,bpInAdd,uiInWidthBytes);
}
*uiOutWidthBytes=uiWidthBytes;
return pNew;
}
示例14: SaperaToBmpFmt
/*************************************************************************
函数名称: SaperaToBmpFmt()
功能描述: 将图像数据从Sapera格式转换到BMP格式
输入参数:
无
输出参数:
无
返 回 值:
TRUE:转换成功 FALSE:转换失败(不支持的数据格式)
其它说明:
BMP格式数据组织方式和Sapera的不同,BMP格式数据从下到上排列,且每行
字节数为4的倍数,Sapera格式数据从上到下,每行字节数为实际宽度对应
字节数。但GDI显示时只支持BMP格式,为了便于其他项目组直接使用算法库,
故作此转换。此外,Sapera格式数据也是算法库采用的格式。
作 者: 周明才
编写时间: 2005.12.16
*************************************************************************/
BOOL CMyDib::SaperaToBmpFmt()
{
WORD wBitCount; // DIB bit count
wBitCount = m_pBMI->bmiHeader.biBitCount;
switch (wBitCount) //只处理8位、24位和32位图像
{
case 8:
case 24:
case 32:
break;
default:
return FALSE;
}
int iWidth = Width();
int iHeight = Height();
int iLineBytes; //每行字节数(BMP格式)
int iWidthBytes; //每行字节数(Sapera格式)
UINT nCount; //BMP格式数据大小(BMP格式)
LPBYTE pbyDataCpy, pbyTmpRes, pbyTmpDst;
// Calculate the number of bytes per line
iLineBytes = WIDTHBYTES(wBitCount * Width());
nCount = iLineBytes * iHeight;
iWidthBytes = (wBitCount * Width()) / 8;
pbyDataCpy = new BYTE[nCount];
memcpy(pbyDataCpy, m_pBits, nCount); //为简单起见,做一份拷贝,
int j;
pbyTmpDst = m_pBits + nCount - iLineBytes;
pbyTmpRes = pbyDataCpy;
//从pbyDataCpy的底部开始取各行数据,对m_pBits从顶部开始填充。
for (j=0; j<iHeight; j++)
{
memcpy(pbyTmpDst, pbyTmpRes, iWidthBytes);
pbyTmpDst -= iLineBytes;
pbyTmpRes += iWidthBytes;
}
delete [] pbyDataCpy;
return TRUE;
}
示例15: WIDTHBYTES
doublemap_t *doublemap_create(int w, int h)
{
int pitch = WIDTHBYTES(w*sizeof(double)*8);
doublemap_t *m;
m = (doublemap_t *)malloc(sizeof(*m)+h*pitch);
assert(m);
if (m == NULL) goto __error_return__;
m->header.width = w;
m->header.height = h;
m->header.pitch = pitch;
m->buffer = (double *)((unsigned char *)m+sizeof(*m));
memset(m->buffer, 0, h*pitch);
return m;
__error_return__:;
return NULL;
}