📄 avifiletcl.cpp
字号:
// avifiletcl.cpp
// Emmanuel Grolleau (c) 2002
// This file is a part of AviCapTcl
// Describes the interface between the class TCLAVIFile and tcl/tk
// Version 1.0.0.0
// Last modification 01/07/2002
#include "avifiletcl.h"
#include "avifile.h"
#define EXTRACT_TCL_INT(obj,intptr) if (Tcl_GetIntFromObj(interp,obj,intptr)==TCL_ERROR) {return TCL_ERROR;}
// Internal functions prototypes/////////////////////////////////////////////////////////////////
int avfDispatch(ClientData clientData, Tcl_Interp *interp,int argc, Tcl_Obj *CONST argv[]);
int avfCmdWrite(ClientData clientData, Tcl_Interp *interp,int argc, Tcl_Obj *CONST argv[]);
int avfCmdClose(ClientData clientData, Tcl_Interp *interp,int argc, Tcl_Obj *CONST argv[]);
/////////////////////////////////////////////////////////////////////////////////////////////////
// Command names
static const char * CmdNames[]= {
"write","close"
};
static const Tcl_ObjCmdProc * CmdProcs[]= {
avfCmdWrite,avfCmdClose
};
static Tcl_HashTable avifileCommands;
// HashTable containing the avifile command names and associated functions
// Implementation
void avifileInit() {
Tcl_InitHashTable(&avifileCommands, TCL_STRING_KEYS);
int ok;
for (int i=0;i<sizeof(CmdProcs)/sizeof(CmdProcs[0]);i++) {
Tcl_HashEntry * entry=Tcl_CreateHashEntry(&avifileCommands, CmdNames[i], &ok);
Tcl_SetHashValue(entry, (ClientData)CmdProcs[i]);
}
}
int avifileCmd(ClientData clientData, Tcl_Interp *interp,int argc, Tcl_Obj *CONST argv[]) {
// Creates a new avifile widget
if (argc<4) {
Tcl_SetResult(interp,"syntax:avifile aviname filepath bmpinfo ?microsecperframe?",TCL_STATIC);
return TCL_ERROR;
}
int microsecperframe;
if (argc==5) {
EXTRACT_TCL_INT(argv[4],µsecperframe);
} else {
microsecperframe=66667;
}
Tcl_CmdInfo cmdinfo;
if (Tcl_GetCommandInfo(interp, Tcl_GetString(argv[1]), &cmdinfo)) {
Tcl_SetResult(interp,"avifile:object already exists",TCL_STATIC);
return TCL_ERROR;
}
Tcl_DString path;
TCLAVIFile *avf=new TCLAVIFile(Tcl_GetString(argv[1]),
Tcl_TranslateFileName(interp, Tcl_GetString(argv[2]), &path),
(LPBITMAPINFO)Tcl_GetByteArrayFromObj(argv[3],0),microsecperframe);
Tcl_DStringFree(&path);
if (!avf->IsOK()) {
Tcl_SetResult(interp,"avifile: error while creating file",TCL_STATIC);
return TCL_ERROR;
}
Tcl_CreateObjCommand(interp, Tcl_GetString(argv[1]), avfDispatch,
(ClientData)avf, (Tcl_CmdDeleteProc *)NULL);
Tcl_SetObjResult(interp,argv[1]);
return TCL_OK;
}
int avfDispatch(ClientData clientData, Tcl_Interp *interp,int argc, Tcl_Obj *CONST argv[]) {
if (argc==1) {
Tcl_SetResult(interp,"avifile: no command given",TCL_STATIC);
return TCL_ERROR;
}
TCLAVIFile *avf=(TCLAVIFile *)clientData;
Tcl_HashEntry * entry=Tcl_FindHashEntry(&avifileCommands, Tcl_GetString(argv[1]));
if (entry==NULL) {
// bad command
static char msg[1024];
memset(msg,0,1024);
strcat(msg,"avifile: bad option ");
strcat(msg,Tcl_GetString(argv[1]));
strcat(msg," must be:");
for (int i=0;i<sizeof(CmdProcs)/sizeof(CmdProcs[0]);i++) {
strcat(msg," ");
strcat(msg,CmdNames[i]);
}
Tcl_SetResult(interp,msg,TCL_STATIC);
return TCL_ERROR;
}
Tcl_ObjCmdProc *proc=(Tcl_ObjCmdProc*)Tcl_GetHashValue(entry);
return (*proc)(clientData,interp,argc,argv);
}
int avfCmdWrite(ClientData clientData, Tcl_Interp *interp,int argc, Tcl_Obj *CONST argv[]) {
if (argc<4) {
Tcl_SetResult(interp,"syntax: aviname write data datalen ?framenumber?",TCL_STATIC);
return TCL_ERROR;
}
int datalen;
EXTRACT_TCL_INT(argv[3],&datalen);
TCLAVIFile *avf=(TCLAVIFile *)clientData;
LPVOID data=(LPVOID)Tcl_GetByteArrayFromObj(argv[2],0);
BOOL result;
if (argc==5) {
int framenb;
EXTRACT_TCL_INT(argv[4],&framenb);
result=!avf->CAVIFile::AddFrame(data,datalen,framenb);
} else {
result=!avf->AddFrame(data,datalen);
}
if (!result) {
Tcl_SetResult(interp,"avifile: failed to write data",TCL_STATIC);
return TCL_ERROR;
}
return TCL_OK;
}
int avfCmdClose(ClientData clientData, Tcl_Interp *interp,int argc, Tcl_Obj *CONST argv[]) {
if (argc!=2) {
Tcl_SetResult(interp,"syntax: aviname close",TCL_STATIC);
return TCL_ERROR;
}
TCLAVIFile *avf=(TCLAVIFile *)clientData;
Tcl_DeleteCommand(interp,Tcl_GetString(argv[0]));
delete avf;
return TCL_OK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -