parent
3072c2525f
commit
0285f20848
10 changed files with 609 additions and 34 deletions
@ -0,0 +1,84 @@ |
||||
//---------------------------------------------------------------------------
|
||||
#include <math.h> |
||||
#include <tchar.h> |
||||
#include <windows.h> |
||||
#include <vfw.h> |
||||
|
||||
#pragma hdrstop |
||||
|
||||
#include "AVIWrite.h" |
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
#pragma package(smart_init) |
||||
#define LENG 10 |
||||
#define PIXELS 100 |
||||
#define WIDTH 160 |
||||
#define HEIGHT 120 |
||||
#define LINE ((((WIDTH)*24+31)&~31)/8) |
||||
#define SIZEIMAGE (LINE*(HEIGHT)) |
||||
|
||||
AVISTREAMINFO si={streamtypeVIDEO,comptypeDIB,0,0,0,0, |
||||
1,10,0,LENG,0,0,(DWORD)-1,0,{0,0,WIDTH,HEIGHT},0,0,_T("Video #1")}; |
||||
BITMAPINFOHEADER bmih={sizeof(BITMAPINFOHEADER),WIDTH,HEIGHT,1,24,BI_RGB, |
||||
SIZEIMAGE,0,0,0,0}; |
||||
//BYTE bBit[SIZEIMAGE];
|
||||
PAVIFILE pavi; |
||||
PAVISTREAM pstm; |
||||
int line,sizeimage; |
||||
|
||||
int AVIWritePrepare(int width,int height,int length, char* filename) |
||||
{ |
||||
//memset(bBit,0,SIZEIMAGE);
|
||||
//AVIFileInit();
|
||||
|
||||
si.dwLength = length; |
||||
|
||||
si.rcFrame.left = 0; //{ 0,0,width,height};
|
||||
si.rcFrame.top = 0; |
||||
si.rcFrame.right = width; |
||||
si.rcFrame.bottom = height; |
||||
|
||||
bmih.biWidth = width; |
||||
bmih.biHeight = height; |
||||
line = ((width*24+31)&~31)/8; |
||||
sizeimage = line*height; |
||||
bmih.biSizeImage = sizeimage; // can be zero?
|
||||
|
||||
//AVIFileInit();
|
||||
|
||||
if (AVIFileOpen(&pavi,(LPCWSTR)filename, |
||||
OF_CREATE | OF_WRITE | OF_SHARE_DENY_NONE,NULL)!=0) |
||||
return 1; |
||||
if (AVIFileCreateStream(pavi,&pstm,&si)!=0) |
||||
return 1; |
||||
if (AVIStreamSetFormat(pstm,0,&bmih,sizeof(BITMAPINFOHEADER))!=0) |
||||
return 1; |
||||
return 0; |
||||
} |
||||
|
||||
int AVIWriteaFrame(int i,char *buffer) |
||||
{ |
||||
if( !buffer ){ |
||||
//ShowMessage("buffer is invalid");
|
||||
return 1; |
||||
} |
||||
if( AVIStreamWrite(pstm,i,1,buffer,sizeimage, |
||||
AVIIF_KEYFRAME,NULL,NULL)!=0) |
||||
return 1; |
||||
return 0; |
||||
|
||||
} |
||||
|
||||
|
||||
int AVIWriteFinish(void) |
||||
{ |
||||
AVIStreamRelease(pstm); |
||||
AVIFileRelease(pavi); |
||||
//AVIFileExit();
|
||||
return 0; |
||||
} |
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,11 @@ |
||||
//---------------------------------------------------------------------------
|
||||
|
||||
#ifndef AVIWriteH |
||||
#define AVIWriteH |
||||
//---------------------------------------------------------------------------
|
||||
#endif |
||||
|
||||
int AVIWritePrepare(int width,int height,int length, char* filename); |
||||
int AVIWriteaFrame(int frame,char *buffer); |
||||
int AVIWriteFinish(void); |
||||
|
@ -0,0 +1,118 @@ |
||||
//---------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
$Log: not supported by cvs2svn $ |
||||
Revision 1.3 2005/03/08 05:55:08 nao |
||||
same strategy as aviimage using AVIStreamOpenFromFile instead of |
||||
AVIFileOpen and AVIFileGetStream for suppress of FD access? |
||||
|
||||
|
||||
*/ |
||||
|
||||
|
||||
//#include <vcl.h>
|
||||
#include <stdio.h> |
||||
#include <tchar.h> |
||||
#include <vfw.h> |
||||
#include "aviimage.h" |
||||
|
||||
aviimage::aviimage() |
||||
{ |
||||
AVIFileInit(); |
||||
} |
||||
|
||||
aviimage::aviimage(wchar_t* fname) |
||||
{ |
||||
wVideo=~0; |
||||
AVIFileInit(); |
||||
AVIStreamOpenFromFile(&pstm,fname,streamtypeVIDEO,0,OF_READ,NULL); |
||||
// AVIFileOpen(&pavi,fname,OF_READ | OF_SHARE_DENY_NONE,NULL);
|
||||
// AVIFileOpen(&pavi,fname,OF_READ ,NULL);
|
||||
// if (AVIFileInfo(pavi,&fi,sizeof(AVIFILEINFO))!=0)
|
||||
// ShowMessage("AVIFileInfo error");
|
||||
// for (dwStream=0;dwStream<fi.dwStreams;dwStream++) {
|
||||
// if (AVIFileGetStream(pavi,&ptmp,0,dwStream)!=0)
|
||||
// ShowMessage("");
|
||||
// if (AVIStreamInfo(ptmp,&si,sizeof(AVISTREAMINFO))!=0)
|
||||
// ShowMessage("");
|
||||
// switch (si.fccType) {
|
||||
// case streamtypeVIDEO:
|
||||
// if (pstm==NULL || si.wPriority<wVideo) {
|
||||
// if (pstm!=NULL)
|
||||
// AVIStreamRelease(pstm);
|
||||
// pstm=ptmp;
|
||||
// wVideo=si.wPriority;
|
||||
// }
|
||||
// continue;
|
||||
// }
|
||||
// AVIStreamRelease(ptmp);
|
||||
// }
|
||||
// above code will not function in Windows XP
|
||||
// it works in 95 and/or 98se mode only
|
||||
//
|
||||
// if(AVIFileGetStream(pavi,&pstm,streamtypeVIDEO,0)!=0)
|
||||
// ShowMessage("AVIFileGetStream");
|
||||
|
||||
if (pstm==NULL) |
||||
ShowMessage("pstm NULL"); |
||||
if ((pfrm=AVIStreamGetFrameOpen(pstm,NULL))==NULL) |
||||
ShowMessage("GetFrameOpen"); |
||||
lStart=AVIStreamStart(pstm); |
||||
lEnd=AVIStreamLength(pstm)+lStart -1; // oops
|
||||
if ((pbmih=(LPBITMAPINFOHEADER)AVIStreamGetFrame(pfrm,0))==NULL) |
||||
ShowMessage("GetFrame error"); |
||||
frect.top = 0; |
||||
frect.left = 0; |
||||
frect.bottom = pbmih->biHeight-1; |
||||
frect.right = pbmih->biWidth-1; |
||||
|
||||
|
||||
} |
||||
|
||||
void aviimage::saveaframe(long fnum, TMemoryStream* out) |
||||
{ |
||||
BITMAPFILEHEADER bmfh; |
||||
|
||||
if ((pbmih=(LPBITMAPINFOHEADER)AVIStreamGetFrame(pfrm,fnum))==NULL) |
||||
ShowMessage("GetFrame error"); |
||||
|
||||
bmfh.bfType=0x4d42; |
||||
bmfh.bfReserved1=bmfh.bfReserved2=0; |
||||
if (pbmih->biClrUsed==0) |
||||
switch (pbmih->biBitCount) { |
||||
case 1:bmfh.bfOffBits=sizeof(RGBQUAD)*2;break; |
||||
case 4:bmfh.bfOffBits=sizeof(RGBQUAD)*16;break; |
||||
case 8:bmfh.bfOffBits=sizeof(RGBQUAD)*256;break; |
||||
case 24:bmfh.bfOffBits=0;break; |
||||
case 16: |
||||
case 32: |
||||
bmfh.bfOffBits=pbmih->biCompression==BI_RGB?0:sizeof(DWORD)*3; |
||||
} |
||||
else |
||||
bmfh.bfOffBits=pbmih->biClrUsed*sizeof(RGBQUAD); |
||||
bmfh.bfOffBits+=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER); |
||||
bmfh.bfSize=bmfh.bfOffBits+(pbmih->biSizeImage==0 |
||||
?((pbmih->biWidth*pbmih->biBitCount+31)&~31)/8*abs(pbmih->biHeight) |
||||
:pbmih->biSizeImage); |
||||
out->Write(&bmfh,sizeof(BITMAPFILEHEADER)); |
||||
out->Write(pbmih,bmfh.bfSize-sizeof(BITMAPFILEHEADER)); |
||||
out->Seek(0,soFromBeginning); |
||||
} |
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void aviimage::finish() |
||||
{ |
||||
if (AVIStreamGetFrameClose(pfrm)!=0) |
||||
ShowMessage(""); |
||||
AVIStreamRelease(pstm); |
||||
AVIFileRelease(pavi); |
||||
AVIFileExit(); |
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,36 @@ |
||||
#ifndef AVIIMAGEH |
||||
#define AVIIMAGEH |
||||
|
||||
//#include <vcl.h>
|
||||
#include <stdio.h> |
||||
#include <tchar.h> |
||||
#include <vfw.h> |
||||
|
||||
|
||||
class aviimage |
||||
{ |
||||
AVIFILEINFO fi; |
||||
AVISTREAMINFO si; |
||||
CHAR szFile[MAX_PATH]; |
||||
DWORD dwStream; |
||||
TRect frect; |
||||
LONG i,lStart,lEnd; |
||||
LPBITMAPINFOHEADER pbmih; |
||||
PAVIFILE pavi; |
||||
PAVISTREAM pstm,ptmp; |
||||
PGETFRAME pfrm; |
||||
WORD wVideo; |
||||
|
||||
public: |
||||
aviimage(); |
||||
aviimage(wchar_t* filename); |
||||
TRect getframerect() { return frect; } |
||||
long getfirst() { return lStart ; } |
||||
long getlast() { return lEnd; } |
||||
void saveaframe(long framenum, TMemoryStream* mem); |
||||
void finish(); |
||||
}; |
||||
|
||||
#endif |
||||
|
||||
|
@ -0,0 +1,151 @@ |
||||
//---------------------------------------------------------------------------
|
||||
|
||||
#include <vcl.h> |
||||
#pragma hdrstop |
||||
#include "aviimage.h" |
||||
#include "AVIWrite.h" |
||||
|
||||
#include "Unit1.h" |
||||
//---------------------------------------------------------------------------
|
||||
#pragma package(smart_init) |
||||
#pragma resource "*.dfm" |
||||
TForm1 *Form1; |
||||
aviimage* work; |
||||
int iw,ih; |
||||
int start,fend; |
||||
|
||||
void playbackavi(aviimage*,int,int); |
||||
void dispaframe(aviimage*, int); |
||||
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TForm1::WMDROPFILES(TWMDropFiles Msg) |
||||
{ |
||||
|
||||
int i; |
||||
char buf[MAX_PATH]; |
||||
TRect f; |
||||
//int iw,ih;
|
||||
|
||||
|
||||
//ドラッグされたファイルの個数
|
||||
int cnt=::DragQueryFile((HDROP)Msg.Drop,0xFFFFFFFF,NULL,0); |
||||
|
||||
for(int i=0;i<cnt;i++){ |
||||
::DragQueryFile((HDROP)Msg.Drop, i,buf,sizeof(buf)); |
||||
// bufにファイル名が入っている
|
||||
Memo1->Lines->Add(AnsiString(buf)); |
||||
|
||||
if( ExtractFileExt(buf) == ".avi" ){ |
||||
work = new aviimage(buf); |
||||
|
||||
//f = AVIImage1->Frame;
|
||||
f = work->getframerect(); |
||||
iw = f.Width(); |
||||
ih = f.Height(); |
||||
start = work->getfirst(); |
||||
fend = work->getlast(); |
||||
Memo1->Lines->Add("Avi file: "+AnsiString(iw)+"x"+AnsiString(ih)); |
||||
Memo1->Lines->Add("start: " + IntToStr(start) + "to " + IntToStr(fend)); |
||||
|
||||
TrackBar1->Min = start; |
||||
TrackBar1->Max = fend; |
||||
dispaframe(work,start); |
||||
//playbackavi(work,start,fend);
|
||||
//playbackavi(work,start,end);
|
||||
//delete work;
|
||||
} |
||||
else if( ExtractFileExt(buf) == ".roi" ){ |
||||
Memo1->Lines->Add("Roi file"); |
||||
} |
||||
else if( ExtractFileExt(buf) == ".bmp" ){ |
||||
Image1->Picture->LoadFromFile(buf); |
||||
} |
||||
|
||||
} |
||||
} |
||||
|
||||
__fastcall TForm1::TForm1(TComponent* Owner) |
||||
: TForm(Owner) |
||||
{ |
||||
DragAcceptFiles(Handle,True); |
||||
Memo1->Lines->Clear(); |
||||
|
||||
} |
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void dispaframe(aviimage* avi,int framenum) |
||||
{ |
||||
//TWICImage* twic = new TWICImage();
|
||||
TImage* targeti; |
||||
TMemoryStream* temp = new TMemoryStream(); |
||||
TBitmap* first = new TBitmap(); |
||||
|
||||
targeti = Form1->Image1; |
||||
targeti->Picture->Bitmap->PixelFormat=pf24bit; // should be 8bit
|
||||
targeti->Width = iw; |
||||
targeti->Picture->Bitmap->Width = iw; |
||||
targeti->Height=ih; |
||||
targeti->Picture->Bitmap->Height = ih; |
||||
|
||||
first->Width = iw; |
||||
first->Height = ih; |
||||
|
||||
Form1->Label1->Caption = IntToStr(framenum); |
||||
|
||||
avi->saveaframe(framenum,temp); |
||||
temp->Position = 0; |
||||
first->LoadFromStream(temp); |
||||
|
||||
//targeti->Picture->Bitmap->LoadFromStream(temp);
|
||||
Form1->Label2->Caption = IntToStr(first->Width); |
||||
Form1->Label3->Caption = IntToStr(first->Height); |
||||
Form1->Image1->Picture->Bitmap->Assign(first); |
||||
targeti->Refresh(); |
||||
|
||||
|
||||
} |
||||
void playbackavi(aviimage* avi,int start, int end) |
||||
{ |
||||
TWICImage* twic = new TWICImage(); |
||||
TImage* targeti; |
||||
TMemoryStream* temp = new TMemoryStream(); |
||||
|
||||
targeti = Form1->Image1; |
||||
targeti->Picture->Bitmap->PixelFormat=pf24bit; // should be 8bit
|
||||
targeti->Width = iw; |
||||
targeti->Picture->Bitmap->Width = iw; |
||||
targeti->Height=ih; |
||||
targeti->Picture->Bitmap->Height = ih; |
||||
|
||||
|
||||
for( int i = start ; i < end ; i++ ){ |
||||
Form1->Label1->Caption = IntToStr(i); |
||||
dispaframe(avi,i); |
||||
//Application->ProcessMessages();
|
||||
//targeti->Refresh();
|
||||
//Form1->Invalidate();
|
||||
} |
||||
|
||||
|
||||
} |
||||
void __fastcall TForm1::TrackBar1Change(TObject *Sender) |
||||
{ |
||||
Label1->Caption = IntToStr(TrackBar1->Position); |
||||
Edit1->Text = IntToStr(TrackBar1->Position); |
||||
dispaframe(work,TrackBar1->Position); |
||||
|
||||
} |
||||
//---------------------------------------------------------------------------
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
||||
void __fastcall TForm1::Edit1Exit(TObject *Sender) |
||||
{ |
||||
Label1->Caption = Edit1->Text; |
||||
TrackBar1->Position = StrToInt(Edit1->Text); |
||||
if( StrToInt(Edit1->Text) < fend ) |
||||
dispaframe(work,StrToInt(Edit1->Text)); |
||||
} |
||||
//---------------------------------------------------------------------------
|
||||
|
Loading…
Reference in new issue