📄 demodlg.cpp
字号:
sx=(w-lWidth)/2;
if(lHeight>=h) sy=0;
else
sy=(h-lHeight)/2;
//
hr=m_pVidWin->SetWindowPosition(sx,sy, lWidth, lHeight);
if(FAILED(hr))
{
goto exit_video;
}
}
//pVidWin->Release();
// Set the owner window to receive event notices.
// 注意此处Filter Graph Manager的事件以WM_GRAPHNOTIFY发出(用户定义的消息).
hr=m_pGraph->QueryInterface(IID_IMediaEventEx, (void **)&m_pEvent);
if(FAILED(hr))
{
goto exit_video;
}
hr=m_pEvent->SetNotifyWindow((OAHWND)GetSafeHwnd(), WM_GRAPHNOTIFY, 0);
// 设置Seeking
hr=m_pGraph->QueryInterface(IID_IMediaSeeking, (void **)&m_pMediaSeeking);
if(FAILED(hr))
{
goto exit_video;
}
// // Run the graph.
//
BOOL ret;
ret=Play();
if(!ret)
{
goto exit_video;
}
//
/*
if(ret==TRUE)
{
// 等待播放结束
long evCode;
m_pEvent->WaitForCompletion(INFINITE, &evCode);
// Stop();
// CleanUp();
// return;
}
*/
//MSG msg;
//hr=m_pVidWin->SetWindowForeground(-1);
if(FAILED(hr))
{
goto exit_video;
}
while(true)
{
// if (::PeekMessage(&msg,NULL,0,0,PM_REMOVE))
// {
// if (msg.message==WM_QUIT)
// {
// PostMessage(-1);
// break;//
// }
// ::TranslateMessage(&msg);
// ::DispatchMessage(&msg);
// }
////////////////////////////////
//m_pVidWin->SetWindowForeground(-1);
//////////////////////////
//m_pVidWin->put_WindowStyle(WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
if(m_all_run_flag==false) break;
if(m_video_finished_flag==true) break;
Sleep(100);
if(m_all_run_flag==false) break;
if(m_video_finished_flag==true) break;
}
exit_video: //
CleanUp();
CoUninitialize();
return;
}
/*
//=========================
//FOR JPEG
HBITMAP CDemoDlg::LoadJpegImage(CString strFileName)
{
FILE * pFile;
JSAMPARRAY pBuffer;
int nRowSize;
//
struct jpeg_error_mgr jerr;
struct jpeg_decompress_struct cinfo;
if ((pFile = fopen(strFileName.GetBuffer(strFileName.GetLength()),"rb")) == NULL) {
//CString strError;
//strError.Format(_T("Can't open file '%s'"), strFileName);
//AfxMessageBox(strError);
return 0;
}
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_decompress(&cinfo);
jpeg_stdio_src(&cinfo, pFile);
jpeg_read_header(&cinfo, TRUE);
jpeg_start_decompress(&cinfo);
ByteArray imageData(cinfo.output_width* cinfo.output_height*3);
nRowSize = cinfo.output_width * cinfo.output_components;
pBuffer = (*cinfo.mem->alloc_sarray)
((j_common_ptr) &cinfo, JPOOL_IMAGE, nRowSize, 1);
while (cinfo.output_scanline < cinfo.output_height)
{
jpeg_read_scanlines(&cinfo, pBuffer, 1);
imageData.Append(pBuffer[0], nRowSize);
//tmpdata=(BYTE *)::malloc(datalen+nRowSize);
//if(tmpdata) return NULL;
//memcpy(tmpdata,imageData,datalen);
//memcpy(tmpdata+datalen,&pBuffer,nRowSize);
//::free(imageData);
//imageData=tmpdata;
}
HBITMAP hBitmap = CSTScreenBuffer::CreateBitmapByRGBArray(imageData.GetData(), cinfo.output_width, cinfo.output_height);
//CSTScreenBuffer m_st;
//HBITMAP hBitmap =m_st.CreateBitmapByRGBArray(imageData.GetData(), cinfo.output_width, cinfo.output_height);
//if(imageData) ::free(imageData);
//if(tmpdata) ::free(tmpdata);
if(!hBitmap) return NULL;
// ASSERT(hBitmap);//???
jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
fclose(pFile);
return hBitmap;
}*/
//
//for gif
HBITMAP CDemoDlg::LoadGifCurFrame(BYTE *imageData,LPCGLOBAL_INFO gi,LPCFRAME fm)
{
//define color table
if(!imageData) return NULL;
//
//BYTE user_myrgb[3*256];
//BYTE myrgb[3*256];
//BYTE *imageData;
BYTE *pColorTable;
if(fm->lFlag)//是局部调色板, // 局部调色板入口数:fm->lSize;
{
pColorTable=fm->pColorTable;
}
else if(gi->gFlag) //全局调色板=有//色板入口数:gi->gSize;
{
pColorTable=gi->gColorTable;
}
else// if(!gi->gFlag&&!fm->lFlag)////全局调色板=无,无局部调色板 :自定义调色板//???
{ //自定义调色板
pColorTable=user_myrgb;
}
/*
//全局调色板是否按优先排序gSort---DEBUG
if(gi->gSort)
{
int g,s;
g=0;
s=g;
}
////局部调色板数据是否按优先排序sortFlag--DEBUG
if(fm->sortFlag)
{
int g,s;
g=0;
s=g;
}*/
long pos1,pos2;
long x,y;
x=fm->imageLPos;
y=fm->imageTPos;
long w,h,H;
// pos0=fm->imageTPos*fm->imageWidth+fm->imageLPos;
//gi->scrWidth gi->scrHeight
// ByteArray imageData(gi->scrHeight* gi->scrHeight*3);
//get data to buffer
/*处置方法(Disposal Method):
指出处置图形的方法,当值为:
0 - 不使用处置方法
1 - 不处置图形,把图形从当前位置移去
2 - 回复到背景色
3 - 回复到先前状态
4-7 - 自定义
注意:
1 - 不处置图形,把图形从当前位置移去
这一句有问题,为1时,应该是保留当前的图像,再绘制一帧图像在上面
*/
//不使用处置方法:0
// BOOL disp_flag;
// disp_flag=true;
if(fm->ctrlExt.active)
{
switch (fm->ctrlExt.disposalMethod)
{
case 1://不处置图形,把图形从当前位置移去--DEBUG
{
//int i,j;
//i=1;
//j=i;
// //disp_flag=false;
}
break;
case 2://回复到背景色
if(gi->gFlag)
{
for( h=0;h<gi->scrHeight ;h++)
for( w=0;w<gi->scrWidth ;w++)
{
//fm->dataBuf[h*fm->imageWidth+w]
//有透明色//图象扩展参数(与透明背景和动画有关)
pos1=(h*gi->scrWidth+w)*3+0;//
// pos1=(h*fm->imageWidth+w)*3+0;//
//gi->scrWidth
pos2=gi->gColorTable[gi->BKColorIdx]*3+0;
//R
imageData[pos1++]=pColorTable[pos2++];
//G
imageData[pos1++]=pColorTable[pos2++];
//B
imageData[pos1]=pColorTable[pos2];
}
}
break;
case 3://回复到先前状态
{
//int i,j;
//i=3;
//j=i;
}
break;
case 0://不使用处置方法
default:
{
//int i,j;
//i=0;
//j=i;
}
break;
}
}
/////////////实际帧数据处理===============================
// if(disp_flag)
{
if(fm->interlaceFlag)//数据是交错的
{//
//long w,h,H;
//T1[0,8,16,8*K]
H=0;
for( h=0;h<fm->imageHeight;h+=8,H++)
for( w=0;w<fm->imageWidth;w++)
{
//fm->dataBuf[h*fm->imageWidth+w]
//有透明色//图象扩展参数(与透明背景和动画有关)
if(fm->ctrlExt.active&&fm->ctrlExt.trsFlag&&
(UINT)(fm->dataBuf[H*fm->imageWidth+w])==(UINT)(fm->ctrlExt.trsColorIndex)
)
{
continue;
}
else
{ pos1=((h+y)*gi->scrWidth+w+x) *3 +0;
//pos1=(h*fm->imageWidth+w) *3 +0;
pos2=fm->dataBuf[H*fm->imageWidth+w]*3+0;
//R
imageData[pos1++]=pColorTable[pos2++];
//G
imageData[pos1++]=pColorTable[pos2++];
//B
imageData[pos1++]=pColorTable[pos2++];
}
}
//T2[4,12,20,4+8*K]
for( h=4;h<fm->imageHeight;h+=8,H++)
for( w=0;w<fm->imageWidth;w++)
{
//fm->dataBuf[h*fm->imageWidth+w]
//有透明色//图象扩展参数(与透明背景和动画有关)
if(fm->ctrlExt.active&&fm->ctrlExt.trsFlag&&
(UINT)(fm->dataBuf[H*fm->imageWidth+w])==(UINT)(fm->ctrlExt.trsColorIndex)
)
{
continue;
}
else
{
pos1=((h+y)*gi->scrWidth+w+x) *3 +0;
//pos1=(h*fm->imageWidth+w) *3 +0;
pos2=fm->dataBuf[H*fm->imageWidth+w]*3+0;
//R
imageData[pos1++]=pColorTable[pos2++];
//G
imageData[pos1++]=pColorTable[pos2++];
//B
imageData[pos1++]=pColorTable[pos2++];
}
}
//T3[2,6,10,2+4*K]
for( h=2;h<fm->imageHeight;h+=4,H++)
for( w=0;w<fm->imageWidth;w++)
{
//fm->dataBuf[h*fm->imageWidth+w]
//有透明色//图象扩展参数(与透明背景和动画有关)
if(fm->ctrlExt.active&&fm->ctrlExt.trsFlag&&
(UINT)(fm->dataBuf[H*fm->imageWidth+w])==(UINT)(fm->ctrlExt.trsColorIndex)
)
{
continue;
}
else
{ pos1=((h+y)*gi->scrWidth+w+x) *3 +0;
// pos1=(h*fm->imageWidth+w) *3 +0;
pos2=fm->dataBuf[H*fm->imageWidth+w]*3+0;
//R
imageData[pos1++]=pColorTable[pos2++];
//G
imageData[pos1++]=pColorTable[pos2++];
//B
imageData[pos1]=pColorTable[pos2];
}
}
//T4[1,3,5,1+2*K]
for( h=1;h<fm->imageHeight;h+=2,H++)
for( w=0;w<fm->imageWidth;w++)
{
//fm->dataBuf[h*fm->imageWidth+w]
//有透明色//图象扩展参数(与透明背景和动画有关)
if(fm->ctrlExt.active&&fm->ctrlExt.trsFlag&&
(UINT)(fm->dataBuf[H*fm->imageWidth+w])==(UINT)(fm->ctrlExt.trsColorIndex)
)
{
continue;
}
else
{
pos1=((h+y)*gi->scrWidth+w+x) *3 +0;
//pos1=(h*fm->imageWidth+w) *3 +0;
pos2=fm->dataBuf[H*fm->imageWidth+w]*3+0;
//R
imageData[pos1++]=pColorTable[pos2++];
//G
imageData[pos1++]=pColorTable[pos2++];
//B
imageData[pos1++]=pColorTable[pos2++];
}
}
}
else//数据是连续的
{
//////////////////////////////////////
//long w,h;
//fm->imageLPos//
//fm->imageTPos//
for( h=0;h<fm->imageHeight;h++)
for( w=0;w<fm->imageWidth;w++)
{
//fm->dataBuf[h*fm->imageWidth+w]
//有透明色//图象扩展参数(与透明背景和动画有关)
if(fm->ctrlExt.active&&fm->ctrlExt.trsFlag&&
(UINT)(fm->dataBuf[h*fm->imageWidth+w])==(UINT)(fm->ctrlExt.trsColorIndex)
)
{
continue;
}
//else
{
pos1=((h+y)*gi->scrWidth+w+x) *3 +0;
//pos1=(h*fm->imageWidth+w) *3 +0;
pos2=fm->dataBuf[h*fm->imageWidth+w]*3+0;
//R
imageData[pos1++]=pColorTable[pos2++];
//G
imageData[pos1++]=pColorTable[pos2++];
//B
imageData[pos1++]=pColorTable[pos2++];
}
//
}
}
}
//create 缓冲位图
HBITMAP hBitmap =CSTScreenBuffer::CreateBitmapByRGBArray(imageData,
gi->scrWidth,
gi->scrHeight
);
if(!hBitmap) return NULL;
//free imageData !!!!!
// ASSERT(hBitmap);//???
//。。。。
return hBitmap;
}
//图片显示方式功能函数
void CDemoDlg::DemoPic(CDC &dc,CDC &MemDC,int w,int h,int fun_in,int fun_out,long speed,long delaytime)
{
int in,out;
in=fun_in;
out=fun_out;
if(fun_in==0)//MAX_ADD_SHOWWAY-2)
{
//get rand seed,
//使每次产生的随机数不一样
SYSTEMTIME st;
GetSystemTime(&st);
unsigned int seed;
seed=st.wHour*3600+st.wMinute*60+st.wSecond;
srand(seed);
int n;
n=rand();
n=n%(MAX_ADD_SHOWWAY-4); // 得到一个0-(MAX_ADD_SHOWWAY-4)的数
//
in=n+1;
}
if(fun_out==0)//MAX_ADD_SHOWWAY-3)//-2
{
//get rand seed,
//使每次产生的随机数不一样
SYSTEMTIME st;
GetSystemTime(&st);
unsigned int seed;
seed=st.wHour*3600+st.wMinute*60+st.wSecond+st.wMilliseconds;
srand(seed);
int n;
n=rand();
n=n%(MAX_ADD_SHOWWAY-5); // 得到一个0-(MAX_ADD_SHOWWAY-5)的数
//
out=n+1;
}
//进入方式
switch(in)
{
case 1://立即进入
{
dc.BitBlt(0,0, w,h,&MemDC,0,0,SRCCOPY);
}
break;
case 2://闪烁进入
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -