void D3D9RenderTargetTexture::GetData(Bitmap &B) { D3DAlwaysValidate(_Device->GetRenderTargetData(_Surface, _SurfacePlain), "GetRenderTargetData"); D3DLOCKED_RECT LockedRect; D3DAlwaysValidate(_SurfacePlain->LockRect(&LockedRect, NULL, 0), "LockRect"); B.Allocate(_Width, _Height); RGBColor *SurfData = (RGBColor*)LockedRect.pBits; for(UINT y = 0; y < _Height; y++) { //memcpy(B[_Height - 1 - y], &SurfData[y * LockedRect.Pitch / 4], _Width * 4); memcpy(B[y], &SurfData[y * LockedRect.Pitch / 4], _Width * 4); } _SurfacePlain->UnlockRect(); }
void D3D9Texture::ReadData(Bitmap &Bmp) { PersistentAssert(_Width != 0 && _Height != 0 && _Format == D3DFMT_A8R8G8B8 && _RenderTarget, "ReadData called on invalid surface"); Bmp.Allocate(_Width, _Height); D3DLOCKED_RECT Rect; D3DAlwaysValidate(_Device->GetRenderTargetData(_SurfaceTopLevel, _SurfacePlain), "GetRenderTargetData"); D3DAlwaysValidate(_SurfacePlain->LockRect(&Rect, NULL, D3DLOCK_READONLY), "LockRect"); BYTE *Bytes = (BYTE *)Rect.pBits; for(UINT y = 0; y < _Height; y++) { RGBColor *CurRow = (RGBColor *)(Bytes + y * Rect.Pitch); for(UINT x = 0; x < _Width; x++) { Bmp[y][x] = CurRow[x]; } } D3DValidate(_SurfacePlain->UnlockRect(), "UnlockRect"); }
void SoftwareGraphicsDevice::CaptureScreen(WindowManager &WM, Bitmap &B) { int i, i2, Width, Height; RECT WindowCoord; RGBColor Color; GetClientRect(WM.CastWindows().GetHWND(), &WindowCoord); MapWindowPoints(WM.CastWindows().GetHWND(), GetDesktopWindow(), (LPPOINT)&WindowCoord, 2); Width = WindowCoord.right - WindowCoord.left; Height = WindowCoord.bottom - WindowCoord.top; //get the Width/Height B.Allocate(Width, Height); //allocate space for(i=0; i<Height; i++) { for(i2=0; i2<Width; i2++) { B[Height-i-1][i2] = Bmp[i][i2]; //load the current screen into B } } }
void ImageCompressorBlockPalette::LoadFromPalette(InputDataStream &stream, Bitmap &bmp) { UINT width, height; stream >> width >> height; bmp.Allocate(width, height); for(UINT x = 0; x < width; x += blockDimension) { for(UINT y = 0; y < height; y += blockDimension) { BYTE paletteIndex; //UINT16 paletteIndex; stream >> paletteIndex; const Block32 &curBlock = _palette.colors[paletteIndex]; for(UINT yOffset = 0; yOffset < blockDimension; yOffset++) { for(UINT xOffset = 0; xOffset < blockDimension; xOffset++) { bmp[y + yOffset][x + xOffset] = curBlock.c[yOffset][xOffset]; } } } } }