3D DirectX



- 6


//

iBitCount = ds.ddpfPixel Format.dwRGBBitCount;

if ((iBitCount != 16) && (iBitCount != 24)) ( return NULL; // He

}

}

ASSERT(ds.dwFlags & DDSD_WIDTH);

int iWidth = ds.dwWidth;

ASSERT(ds.dwFlags & DDSD_HEIGHT) ;

int iHeight = ds.dwHeight;

// , int iCIrTabEntries = 0;

if (ds.ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED8

// iCIrTabEntries = 256;

iBitCount = 8;

// BITMAPINFO, int iSize = sizeof(BITMAPINFO) + iCIrTabEntries * sizeof(RGBQUAD) ;

BITMAPINFO* pBMI = (BITMAPINFO*) new BYTE[iSize];

memsetfpBMI, 0, iSize);

pBMI-bmiHeader.biSize = sizeof(BITMAPINFOHEADER);

pBMI-bmiHeader.biWidth = iWidth;

pBMI-bmiHeader.biHeight = iHeight;

pBMI-bmiHeader. biPlanes = 1;

pBMI-bmiHeader.biBitCount = iBitCount;

pBMI-bmiHeader.biClrUsed = iCIrTabEntries;

HOC hdcScreen = ::GetDC(NULL) ;

// , if (iCIrTabEntries 0) (

ASSERT(iClrTabEntries= 256);

PALETTEENTRY [256];

''illi' 257

ASSERT(m_pPalette) ;

m_pPalette-GetInterface () -GetEntries (0, 0,

iCIrTabEntries, pe) ;

for (int i = 0; i iCIrTabEntries; i++) ( pBMI-bmiColors [i] .rgbRed = pe[i].peRed;

pBMI-bmiColors [i] .rgbGreen = pe[i].peGreen;

pBMI-bmiColors [i] .rgbBlue = pe[i].peBlue;

} >

// DIB-,

//

BYTE* pBits = NULL;

HBITMAP hBmp = ::CreateDIBSection(hdcScreen, pBMI,

DIB_RGB_COLORS, (VOID**)&pBits, NULL, 0);

::ReleaseDC(NULL, hdcScreen);

if (!hBmp) { delete pBMI;

return NULL;

}

ASSERT(pBits) ;

// DIB

int iDIBScan =

( ( (pBMI-bmiHeader.biWidth

* pBMI-bmiHeader.biBitCount) + 31) & -31) 3;

int iSurfScan = ds.lPitch;

BYTE* pDIBLine = pBits + (iHeight - 1) * iDIBScan;

BYTE* pSurfLine = (BYTE*)ds.IpSurface;