You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
232 lines
5.2 KiB
232 lines
5.2 KiB
//--------------------------------------------------------------------------- |
|
|
|
#include <fmx.h> |
|
#pragma hdrstop |
|
#include <FMX.Platform.Win.hpp> |
|
#include <ShellAPI.h> |
|
#include <cstdlib> |
|
#include <memory> |
|
#include <vector> |
|
#include <iostream> |
|
#include "aviimage.h" |
|
#include "AVIWrite.h" |
|
|
|
|
|
#include "Unit1.h" |
|
//--------------------------------------------------------------------------- |
|
#pragma package(smart_init) |
|
#pragma resource "*.fmx" |
|
|
|
#if _WIN64 |
|
#define Parm GWLP_WNDPROC |
|
#elif _WIN32 |
|
#define Parm GWL_WNDPROC |
|
#elif __APPLE__ |
|
// macOS |
|
#else |
|
#error Not a supported platform |
|
#endif |
|
|
|
std::vector <AnsiString>filenames; |
|
aviimage* work; |
|
int iw,ih; |
|
int start,fend; |
|
|
|
void playbackavi(aviimage*,int,int); |
|
void dispaframe(aviimage*, int); |
|
|
|
|
|
TForm1 *Form1; |
|
//--------------------------------------------------------------------------- |
|
|
|
/* |
|
void __fastcall TForm1::msg_hnd(TWMDropFiles Msg) |
|
{ |
|
int count; |
|
int i; |
|
char fname[256]; |
|
|
|
count=DragQueryFile((HDROP)Msg.Drop, 0xFFFFFFFF, NULL, 255); |
|
DragQueryFile((HDROP)Msg.Drop, 0, fname, 255); |
|
///ファイル処理(fname); |
|
Memo1->Lines->Add(fname); |
|
if (count>1) { |
|
for(i=1;i<count;i++) { |
|
DragQueryFile((HDROP)Msg.Drop, i, fname, 255); |
|
//ファイル処理2(fname) |
|
Memo1->Lines->Add(fname); |
|
} |
|
} |
|
DragFinish((HDROP)Msg.Drop); // メモリ開放 |
|
} |
|
*/ |
|
|
|
HWND m_Hwnd; |
|
|
|
WNDPROC m_WndOldProc; |
|
|
|
long m_OldWndProc; |
|
|
|
/* |
|
const unsigned int count = DragQueryFile((HDROP)Message.Drop, -1, NULL, 0); |
|
for (unsigned int i = 0; i < count; ++i) |
|
{ |
|
|
|
*/ |
|
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->Bitmap->Width = iw; |
|
targeti->Height=ih; |
|
targeti->Bitmap->Height = ih; |
|
|
|
first->Width = iw; |
|
first->Height = ih; |
|
|
|
Form1->Label1->Text = IntToStr(framenum); |
|
|
|
avi->saveaframe(framenum,temp); |
|
temp->Position = 0; |
|
first->LoadFromStream(temp); |
|
|
|
//targeti->Picture->Bitmap->LoadFromStream(temp); |
|
Form1->Label2->Text = IntToStr(first->Width); |
|
Form1->Label3->Text = IntToStr(first->Height); |
|
Form1->Image1->Bitmap->Assign(first); |
|
targeti->Repaint(); |
|
|
|
|
|
} |
|
void playbackavi(aviimage* avi,int start, int end) |
|
{ |
|
TImage* targeti; |
|
TMemoryStream* temp = new TMemoryStream(); |
|
|
|
targeti = Form1->Image1; |
|
//targeti->Bitmap->PixelFormat=pf24bit; // should be 8bit |
|
targeti->Width = iw; |
|
targeti->Bitmap->Width = iw; |
|
targeti->Height=ih; |
|
targeti->Bitmap->Height = ih; |
|
|
|
|
|
for( int i = start ; i < end ; i++ ){ |
|
Form1->Label1->Text = IntToStr(i); |
|
dispaframe(avi,i); |
|
//Application->ProcessMessages(); |
|
//targeti->Refresh(); |
|
//Form1->Invalidate(); |
|
} |
|
|
|
|
|
} |
|
|
|
LRESULT CALLBACK WndProc(HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam) |
|
{ |
|
int count; |
|
int i; |
|
char fname[256]; |
|
TRect f; |
|
|
|
|
|
if(Msg == WM_DROPFILES){ |
|
|
|
//ShowMessage("drop files fired and catched"); |
|
|
|
const unsigned int count = DragQueryFile((HDROP)wParam,-1,NULL,0); |
|
for( unsigned int i = 0 ; i < count ; ++i ){ |
|
const unsigned int length = DragQueryFile((HDROP)wParam, i, NULL, 0); |
|
std::unique_ptr<wchar_t[]> filename(new wchar_t[length + 1]); |
|
|
|
//ドロップされたファイルの名前を取得する |
|
DragQueryFile((HDROP)wParam, i, filename.get(), length + 1); |
|
UnicodeString temp; |
|
temp = filename.get(); |
|
//Form1->Memo1->Lines->Add(temp); |
|
//filenames.push_back(temp); |
|
Form1->Memo1->Lines->Add(temp); |
|
|
|
if( ExtractFileExt(temp) == ".avi" ){ |
|
work = new aviimage(temp.c_str()); |
|
|
|
//f = AVIImage1->Frame; |
|
f = work->getframerect(); |
|
iw = f.Width(); |
|
ih = f.Height(); |
|
start = work->getfirst(); |
|
fend = work->getlast(); |
|
Form1->Memo1->Lines->Add("Avi file: "+AnsiString(iw)+"x"+AnsiString(ih)); |
|
Form1->Memo1->Lines->Add("start: " + IntToStr(start) + "to " + IntToStr(fend)); |
|
|
|
Form1->TrackBar1->Min = start; |
|
Form1->TrackBar1->Max = fend; |
|
dispaframe(work,start); |
|
//playbackavi(work,start,fend); |
|
//playbackavi(work,start,end); |
|
//delete work; |
|
} |
|
else if( ExtractFileExt(temp) == ".roi" ){ |
|
Form1->Memo1->Lines->Add("Roi file"); |
|
} |
|
else if( ExtractFileExt(temp) == ".bmp" ){ |
|
Form1->Image1->Bitmap->LoadFromFile(temp); |
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return CallWindowProc(m_WndOldProc,hWnd,Msg,wParam,lParam); |
|
|
|
} |
|
|
|
__fastcall TForm1::TForm1(TComponent* Owner) |
|
: TForm(Owner) |
|
{ |
|
|
|
|
|
m_Hwnd = Fmx::Platform::Win::FormToHWND(Form1); |
|
DragAcceptFiles(m_Hwnd,true); |
|
|
|
m_OldWndProc = GetWindowLongPtr(m_Hwnd, Parm); |
|
m_WndOldProc = (WNDPROC)SetWindowLongPtr(m_Hwnd, Parm,(LONG)WndProc); |
|
|
|
} |
|
|
|
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action) |
|
{ |
|
SetWindowLongPtr(m_Hwnd,Parm,m_OldWndProc); |
|
} |
|
|
|
|
|
void __fastcall TForm1::TrackBar1Change(TObject *Sender) |
|
{ |
|
Label1->Text = IntToStr((int)TrackBar1->Value); |
|
Edit1->Text = IntToStr((int)TrackBar1->Value); |
|
dispaframe(work,TrackBar1->Value); |
|
|
|
} |
|
//--------------------------------------------------------------------------- |
|
|
|
void __fastcall TForm1::Edit1Exit(TObject *Sender) |
|
{ |
|
Label1->Text = Edit1->Text; |
|
TrackBar1->Value = StrToInt(Edit1->Text); |
|
if( StrToInt(Edit1->Text) < fend ) |
|
dispaframe(work,StrToInt(Edit1->Text)); |
|
|
|
} |
|
//--------------------------------------------------------------------------- |
|
|
|
|