/* --------------------------------------------------------------------------------------- - Grabs A Frame From The Stream --------------------------------------------------------------------------------------- */ void AviVideoRenderer::GrabAVIFrame(int frame) { LPBITMAPINFOHEADER lpbi; // Holds The Bitmap Header Information lpbi = (LPBITMAPINFOHEADER)AVIStreamGetFrame(_AVR_pgf, frame); // Grab Data From The AVI Stream char* _tex_pdata=(char *)lpbi+lpbi->biSize+lpbi->biClrUsed * sizeof(RGBQUAD); // Pointer To Data Returned By AVIStreamGetFrame // Convert Data To Requested Bitmap Format DrawDibDraw (_AVR_hdd, _AVR_hdc, 0, 0, _heights[0], _widths[0], lpbi, _tex_pdata, 0, 0, _video_width, _video_height, 0); flipIt(_img_data, _heights[0], _widths[0]); // Swap The Red And Blue Bytes (GL Compatability) // Update The Texture glBindTexture(GL_TEXTURE_2D, _textures[0]); glTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, _heights[0], _widths[0], GL_RGB, GL_UNSIGNED_BYTE, _img_data); }
static void __fastcall Repaint(HWND hWnd,RECT & updata,RECT& upbmp,HDC hdc) { PAINTSTRUCT ps={0}; HDRAWDIB hdd; HBITMAP hbmp; BITMAPINFOHEADER bi={sizeof(bi)}; void* bits=LocalAlloc(LPTR,4096*4096*5); POINTS bmprc; *((DWORD*)(&bmprc))= GetWindowLong(hWnd,FIELD_OFFSET(ShowPicClass,bmRC)); hdd=DrawDibOpen(); if(!hdc) hdc =BeginPaint(hWnd,&ps); hbmp=(HBITMAP)GetWindowLong(hWnd,FIELD_OFFSET(ShowPicClass,hbmp)); BITMAP bm; GetObject(hbmp,sizeof(bm),&bm); bi.biBitCount=32; bi.biWidth = bm.bmWidth; bi.biPlanes = 1; bi.biHeight = bm.bmHeight ; ExcludeClipRect(hdc,updata.left,updata.top,updata.right,updata.bottom); FillRect(hdc,&ps.rcPaint,(HBRUSH)1); SelectClipRgn(hdc,NULL); GetDIBits(hdc,hbmp,0,bi.biHeight,bits,(LPBITMAPINFO)&bi,DIB_RGB_COLORS); DrawDibDraw(hdd,hdc,updata.left,updata.top,updata.right-updata.left,updata.bottom-updata.top, &bi,bits,upbmp.left,upbmp.top,upbmp.right-upbmp.left,upbmp.bottom-upbmp.top,0); LocalFree(bits); DrawDibClose(hdd); if(ps.hdc) EndPaint(hWnd,&ps); }
void CWebCamDlg::OnPaint() { CPaintDC dc(this); // device context for painting // TODO: Add your message handler code here RECT rect; GetClientRect(&rect); DrawDibDraw ( m_hDD, m_hDC, 0, 0, rect.right, rect.bottom, &m_bmih, m_lpScreenDIB, 0, 0, m_bmih.biWidth, m_bmih.biHeight, DDF_SAME_HDC ); // Do not call CDialog::OnPaint() for painting messages }
void tTVPDrawer_GDIDoubleBuffering::NotifyBitmapCompleted(tjs_int x, tjs_int y, const void * bits, const BITMAPINFO * bitmapinfo, const tTVPRect &cliprect) { // DrawDibDraw にて OffScreenDC に描画を行う if(DrawDibHandle && OffScreenDC) { ShouldShow = true; DrawDibDraw(DrawDibHandle, OffScreenDC, x, y, cliprect.get_width(), cliprect.get_height(), const_cast<BITMAPINFOHEADER*>(reinterpret_cast<const BITMAPINFOHEADER*>(bitmapinfo)), const_cast<void*>(bits), cliprect.left, cliprect.top, cliprect.get_width(), cliprect.get_height(), 0); } }
void VideoDlg::OnPaint() { CPaintDC dc(this); // device context for painting /* CRect rect; GetClientRect(&rect); CFont font; int nHeight = -((dc.GetDeviceCaps (LOGPIXELSY) * 20) / 72); font.CreateFont (nHeight, 0, 0, 0, FW_BOLD, TRUE, 0, 0, DEFAULT_CHARSET, OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Times New Roman"); //dc.SetBkMode (TRANSPARENT); dc.SetBkColor(RGB(255,0,255)); dc.SetTextColor (RGB (255, 255, 255)); CFont* pOldFont = dc.SelectObject (&font); dc.DrawText ("Hello, MFC", -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER); dc.SelectObject (pOldFont);*/ Write2Log("Up to frame %d",m_oAVIReader.CurrentFrame()); LPBITMAPINFOHEADER pBMP = m_oAVIReader.GetCurrentFrame(); if(!pBMP) return; SaveBMP(pBMP,"test.bmp"); byte* pdata=(byte*)pBMP+pBMP->biSize+pBMP->biClrUsed*sizeof(RGBQUAD); // Convert Data To Requested Bitmap Format & Draw IT!!! DrawDibDraw(m_hdd, dc.GetSafeHdc(), 32, 32, pBMP->biWidth, pBMP->biHeight, pBMP, pdata, 0, 0, m_oAVIReader.Width(), m_oAVIReader.Height(), 0); }
void AVI :: Set(float time) // Grabs A Frame From The Stream { // anything to do? if(!tman || mpf==0) NTHROW("AVI :: Set - Video not created before call to set."); // move position forward by time pos+=time; // get the frame number int frame=(int)((float)pos/mpf); // have we gone past the end? if(frame>=lastframe) { if(loop) { pos=0.0f; frame=0; // reset the animation }else frame=lastframe-1; // hold at the last frame } LPBITMAPINFOHEADER lpbi; // Holds The Bitmap Header Information lpbi = (LPBITMAPINFOHEADER)AVIStreamGetFrame(pgf, frame); // Grab Data From The AVI Stream pdata=(BYTE *)lpbi+lpbi->biSize+lpbi->biClrUsed * sizeof(RGBQUAD); // Pointer To Data Returned By AVIStreamGetFrame // Convert Data To Requested Bitmap Format DrawDibDraw (hdd, hdc, 0, 0, 256, 256, lpbi, pdata, 0, 0, width, height, 0); flipIt(data); // Swap The Red And Blue Bytes (GL Compatability) // set our texture tman->Set(texid); // Update The Texture glTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, 256, 256, GL_RGB, GL_UNSIGNED_BYTE, data); }
// Several interesting things happen here: 1) We copy the DIB onto // our own bitmap (hMemDC), with DrawDibDraw, then we draw rectangles // onto that bitmap (or not) as we walk down the hotspot list (with // Rectangle), then we BitBlt the result onto the screen. I've heard // rumors that this could be done with the DIB driver and get rid of // the extra image copy. static LONG NEAR PASCAL AVIDraw(PINSTINFO pi, ICDRAW FAR *lpicd, LONG cbicd) { UINT wFlags; wFlags = DDF_SAME_HDC; if ((lpicd->dwFlags & ICDRAW_NULLFRAME) || lpicd->lpData == NULL) { if (lpicd->dwFlags & ICDRAW_UPDATE) { wFlags |= DDF_UPDATE; } else { return ICERR_OK; } } if (lpicd->dwFlags & ICDRAW_PREROLL) { wFlags |= DDF_DONTDRAW; } if (lpicd->dwFlags & ICDRAW_HURRYUP) { wFlags |= DDF_HURRYUP; } if (pi->lpMovie) { if(!DrawDibDraw(pi->hdd, pi->hMemdc, 0,0, pi->dxDst, pi->dyDst, lpicd->lpFormat, lpicd->lpData, pi->xSrc, pi->ySrc, pi->dxSrc, pi->dySrc, wFlags)) { OutputDebugString("Error: DrawDibDraw Bombed!\n"); } else { PHOTSPOT pHotspot; pHotspot = (pi->lpMovie)->pHotspotList; while (pHotspot) { if ((pHotspot->BeginFrame < lpicd->lTime) && (pHotspot->EndFrame > lpicd->lTime)) { Rectangle(pi->hMemdc, pHotspot->rc.left, pHotspot->rc.top, pHotspot->rc.right, pHotspot->rc.bottom); } pHotspot = pHotspot->pNext; } BitBlt(pi->hdc,pi->xDst,pi->yDst,pi->dxDst,pi->dyDst, pi->hMemdc,0,0,SRCCOPY); } } else if (!DrawDibDraw(pi->hdd, pi->hdc, pi->xDst, pi->yDst, pi->dxDst, pi->dyDst, lpicd->lpFormat, lpicd->lpData, pi->xSrc, pi->ySrc, pi->dxSrc, pi->dySrc, wFlags)) { if (wFlags & DDF_UPDATE) { return ICERR_CANTUPDATE; } else { return ICERR_UNSUPPORTED; } } return ICERR_OK; }
static FIMULTIBITMAP* ReadFromAvi(const char* filename) { int err=0; AVIFileInit(); PAVISTREAM pavi; // Handle To An Open Stream if( AVIStreamOpenFromFile(&pavi, filename, streamtypeVIDEO, 0, OF_READ, NULL) != 0) { AVIFileExit(); return NULL; } AVISTREAMINFO psi; // Pointer To A Structure Containing Stream Info AVIStreamInfo(pavi, &psi, sizeof(psi)); // Reads Information About The Stream Into psi int width = psi.rcFrame.right-psi.rcFrame.left; // Width Is Right Side Of Frame Minus Left int height = psi.rcFrame.bottom-psi.rcFrame.top; // Height Is Bottom Of Frame Minus Top int frameCount = AVIStreamLength(pavi); // The Last Frame Of The Stream double mpf = AVIStreamSampleToTime(pavi, frameCount) / (double)frameCount; // Calculate Rough Milliseconds Per Frame PGETFRAME pgf = AVIStreamGetFrameOpen(pavi, NULL); // Create The PGETFRAME Using Our Request Mode if (pgf==NULL) { // An Error Occurred Opening The Frame error("Failed To Open frame from AVI"); } //HDC hdc = GetDC(0); HDRAWDIB hdd = DrawDibOpen(); // Handle For Our Dib BITMAPINFOHEADER bmih; // Header Information For DrawDibDraw Decoding bmih.biSize = sizeof (BITMAPINFOHEADER); // Size Of The BitmapInfoHeader bmih.biPlanes = 1; // Bitplanes bmih.biBitCount = 24; // Bits Format We Want (24 Bit, 3 Bytes) bmih.biWidth = width; // Width We Want (256 Pixels) bmih.biHeight = height; // Height We Want (256 Pixels) bmih.biCompression = BI_RGB; // Requested Mode = RGB char *data; // Pointer To Texture Data HBITMAP hBitmap = CreateDIBSection(hdc, (BITMAPINFO*)(&bmih), DIB_RGB_COLORS, (void**)(&data), NULL, NULL); SelectObject(hdc, hBitmap); // Select hBitmap Into Our Device Context (hdc) // create a new freeimage anim someError=false; FIMULTIBITMAP* ret = FreeImage_OpenMultiBitmap(FIF_TIFF, "temp.tiff", TRUE, FALSE); if (!ret || someError) { error("Couldnt create multibitmap"); } for (int frame=0; frame<frameCount; frame++) { fprintf(stderr, "Loading frame %i\n", frame); // Grab Data From The AVI Stream LPBITMAPINFOHEADER lpbi = (LPBITMAPINFOHEADER)AVIStreamGetFrame(pgf, frame); // Pointer To Data Returned By AVIStreamGetFrame // (Skip The Header Info To Get To The Data) char* pdata = (char *)lpbi + lpbi->biSize + lpbi->biClrUsed * sizeof(RGBQUAD); // Convert Data To Requested Bitmap Format DrawDibDraw(hdd, hdc, 0, 0, width, height, lpbi, pdata, 0, 0, width, height, 0); // copy into the freeimage thing FIBITMAP* fiBitmap = FreeImage_ConvertFromRawBits((BYTE*)data, width, height, width*3, 24, 0xFF0000, 0x00FF00, 0x0000FF); /* BYTE* src = (BYTE*)data; for (int y=0; y<height; y++) { BYTE* dst = FreeImage_GetScanLine(fiBitmap, y); for (int x=0; x<width; x++) { //src++; *dst++ = *src++; *dst++ = *src++; *dst++ = *src++; } } */ FIBITMAP* grayBitmap = FreeImage_ConvertToGreyscale(fiBitmap); FreeImage_Unload(fiBitmap); FreeImage_AppendPage(ret, grayBitmap); } FreeImage_CloseMultiBitmap(ret); ret = FreeImage_OpenMultiBitmap(FIF_TIFF, "temp.tiff", FALSE, TRUE); DeleteObject(hBitmap); // Delete The Device Dependant Bitmap Object DrawDibClose(hdd); // Closes The DrawDib Device Context AVIStreamGetFrameClose(pgf); // Deallocates The GetFrame Resources AVIStreamRelease(pavi); // Release The Stream AVIFileExit(); // Release The File return ret; }