void DGLBlitterBase::blit(unsigned int width, unsigned int height, unsigned int rowBytes, gl_t format, gl_t type, const void* data) { m_SrcStride = rowBytes; m_Width = width; m_Height = height; m_DataFormat = GLFormats::getDataFormat(format); m_DataType = GLFormats::getDataType(type); if (!m_DataFormat || !m_DataType) { throw std::runtime_error( "Got image of unknown type and format. It may be debugger bug"); } m_SrcData = data; doBlit(); }
int _tmain(int argc, _TCHAR* argv[]) { if(argc<2) { APP_ERROR("Please type %s aviFileName\n", argv[0]); return -1; } int pos; MainAVIHeader *psAviH; //integrityCheck(argv[1]); int nAviStrhPos; struct AVI_strh *psAviStrH; DWORD nMainAvihSize; int nSize; BYTE *pHdrl; int nVidsNo; SDL_Surface *screen; nSize = aviHdrlBufferGet(argv[1], &pHdrl); if (nSize < 0) return -1; pos = aviHeaderGetFromHdrl(pHdrl, nSize, &nMainAvihSize); if (pos >= 0) { psAviH = (MainAVIHeader *)(pHdrl + pos); nAviStrhPos = vidsStrhGetFromHdrl(pHdrl, nSize, psAviH->dwStreams, &nVidsNo); if (nAviStrhPos > 0) { psAviStrH = (struct AVI_strh *)(pHdrl + nAviStrhPos); } } //create screen according to W x H. screen = sdlMainScreenInit(psAviH->dwWidth, psAviH->dwHeight); Uint32 nTicksInc = (psAviH->dwMicroSecPerFrame)/1000; Uint32 nTicksIncUs = (psAviH->dwMicroSecPerFrame); printf("\tFrame interval is %d Ms\n", nTicksInc); //release memory free(pHdrl); //create decode thread. VideoState aviStream; memset(&aviStream, 0 , sizeof(aviStream)); strcpy(aviStream.filename, argv[1]); aviStream.screen = screen; aviStream.mutex = SDL_CreateMutex(); aviStream.cond = SDL_CreateCond(); aviStream.bBlited = 1; aviStream.bFliped = 1; //aviStream.nTicksInc = nTicksInc; aviStream.parse_tid = SDL_CreateThread(decode_thread, &aviStream); if(!aviStream.parse_tid) { SDL_Quit(); return -1; } SDL_Event event; int res; Uint32 nRefreshTicks = 0; for(;;) { SDL_WaitEvent(&event); switch(event.type) { case SDL_KEYDOWN: switch (event.key.keysym.sym) { case SDLK_SPACE: if(!aviStream.pause) { aviStream.pause = 1; printf("\t\t pause!\n"); } else { //reset time control if(REFRESH_TIME_CTRL == TIME_CTRL_0) { nRefreshTicks = 0; } else { aviStream.nCurFrameCnt = 0; aviStream.nRefTicks = 0; } printf("\n\n resume!\n"); SDL_LockMutex(aviStream.mutex); aviStream.pause = 0; SDL_CondSignal(aviStream.cond); SDL_UnlockMutex(aviStream.mutex); } break; } break; case PW_QUIT_EVENT: case SDL_QUIT: aviStream.quit = 1; SDL_CondSignal(aviStream.cond); SDL_WaitThread(aviStream.parse_tid, NULL); SDL_Quit(); SDL_DestroyCond(aviStream.cond); SDL_DestroyMutex(aviStream.mutex); return 0; break; case PW_FRAME_REPEAT: if(REFRESH_TIME_CTRL == TIME_CTRL_0) { //we not plan to support for TIME_CTRL_0 mode. } else { // we just need to advanced the cnt, then next frame refresh would has such delay time. aviStream.nCurFrameCnt++; //for repeat frame case, if it is first frame, we needs update the nRefTicks if(1 == aviStream.nCurFrameCnt) { aviStream.nRefTicks = SDL_GetTicks(); } printf("\t\t [%d] frame repeat. frame timing ctrl 1\n", aviStream.nCurFrameCnt); } break; case PW_BLIT_EVENT: res = doBlit(event.user.data1); //schedule refresh timer if blit success. Or do nothing if postponed. if (res) { if(REFRESH_TIME_CTRL == TIME_CTRL_0) { Uint32 ticks; ticks = SDL_GetTicks(); int delay; static int nFrameCnt = 0; delay = (nRefreshTicks > ticks)? (nRefreshTicks - ticks) : 0; schedule_refresh(&aviStream, delay); printf("\t\t[%d] delay tick = %d Ms. frame timing ctrl 0\n", nFrameCnt, delay); nFrameCnt++; } else { aviStream.nCurFrameCnt++; Uint32 nTargetTicks; nTargetTicks = aviStream.nRefTicks + ((aviStream.nCurFrameCnt)*nTicksIncUs)/1000; Uint32 ticks; ticks = SDL_GetTicks(); int delay; delay = (nTargetTicks > ticks)? (nTargetTicks - ticks) : 0; schedule_refresh(&aviStream, delay); //printf("\t\t [%d] delay tick = %d Ms. frame timing ctrl 1\n", aviStream.nCurFrameCnt, delay); printf("\t\t [%d] delay tick = %d Ms. Show at %d Ms. frame timing ctrl 1\n", aviStream.nCurFrameCnt, delay, nTargetTicks-aviStream.nRefTicks); } } break; case PW_FLIP_EVENT: if(REFRESH_TIME_CTRL == TIME_CTRL_0) { //update nRefreshTicks Uint32 ticks; ticks = SDL_GetTicks(); nRefreshTicks = ticks + nTicksInc; //printf("\t\t Refresh tick = %d Ms\n", ticks); } else { if(1 == aviStream.nCurFrameCnt) { aviStream.nRefTicks = SDL_GetTicks(); } } doRefresh(event.user.data1); break; default: break; } } return 0; }
void DGLBlitterBase::setChannelScale(Channel channel, float scale, float bias) { m_ChannelScaleBiases[channel] = std::pair<float, float>(scale, bias); if (m_DataFormat && m_DataType) { doBlit(); } }