1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083
|
#define PROMPT "grabsh: "
#include "tcl.h"
#include "tk.h"
#include "show.h"
#include "dither.h"
#include "video.h"
#include <sys/time.h>
#include <string.h>
#include <sys/stat.h>
#include <assert.h>
#define TRUE 1
#define FALSE 0
/**********************************************************************/
/*
* Command used to initialize wish:
*/
/* was wish.tcl */
char initCmd[] = "source $tk_library/tk.tcl";
Tk_Window mywin;
Tk_Window w; /* NULL means window has been deleted. */
Tk_TimerToken timeToken = 0;
int idleHandler = 0;
Tcl_Interp *interp;
int x, y;
int inPlayLoop = FALSE;
char title[512];
jmp_buf env2;
char ditherName[512];
int movieOpen = FALSE;
int numBytes = 0;
double stopStartTime;
int justShowOne = FALSE;
float percentPlay = 1.0;
char program[1024];
int firstTimePlayed = 1;
extern FILE *input;
extern VidStream *theStream;
extern int justRewound;
void PlayLoop();
void ContinuePlayLoop();
extern double ReadSysClock();
static Window winID;
static Display *winDisplay;
static GC gc;
int globalCommand = NO_COMMAND;
float realFPS;
#ifdef BLEAH
Tcl_CmdBuf buffer;
#endif
int tty;
extern int Tk_SquareCmd _ANSI_ARGS_((ClientData clientData,
Tcl_Interp *interp, int argc, char **argv));
/*
* Information for testing out command-line options:
*/
int synchronize = 0;
char *fileName = NULL;
char *name = NULL;
char *displayName = NULL;
char *geometry = NULL;
Tk_ArgvInfo argTable[] = {
{"-file", TK_ARGV_STRING, (char *) NULL, (char *) &fileName,
"File from which to read commands"},
{"-geometry", TK_ARGV_STRING, (char *) NULL, (char *) &geometry,
"Initial geometry for window"},
{"-display", TK_ARGV_STRING, (char *) NULL, (char *) &displayName,
"Display to use"},
{"-name", TK_ARGV_STRING, (char *) NULL, (char *) &name,
"Name to use for application"},
{"-sync", TK_ARGV_CONSTANT, (char *) 1, (char *) &synchronize,
"Use synchronous mode for display server"},
{(char *) NULL, TK_ARGV_END, (char *) NULL, (char *) NULL,
(char *) NULL}
};
#ifdef BLEAH
void StdinProc(clientData, mask)
ClientData clientData; /* Not used. */
int mask;
{
char line[200];
static int gotPartial = 0;
char *cmd;
int result;
if (mask & TK_READABLE) {
if (fgets(line, 200, stdin) == NULL) {
if (!gotPartial) {
if (tty) {
Tcl_Eval(interp, "destroy .", 0, (char **) NULL);
exit(0);
} else {
Tk_DeleteFileHandler(0);
}
return;
} else {
line[0] = 0;
}
}
cmd = Tcl_AssembleCmd(buffer, line);
if (cmd == NULL) {
gotPartial = 1;
return;
}
gotPartial = 0;
result = Tcl_RecordAndEval(interp, cmd, 0);
if (*interp->result != 0) {
if ((result != TCL_OK) || (tty)) {
printf("%s\n", interp->result);
}
}
if (tty) {
printf(Tcl_GetVar (interp, "prompt", TCL_GLOBAL_ONLY));
fflush(stdout);
}
}
}
#endif
static void StructureProc(clientData, eventPtr)
ClientData clientData; /* Information about window. */
XEvent *eventPtr; /* Information about event. */
{
if (eventPtr->type == DestroyNotify) {
w = NULL;
}
}
int OrigSizeC(nulldata, interp, argc, argv)
ClientData nulldata;
Tcl_Interp *interp;
int argc;
char **argv;
{
char command[256];
extern int origWidth, origHeight;
extern int windowWidth, windowHeight;
extern int oldBytesRead;
windowWidth = origWidth+2*IMAGE_LEFT;
if ( windowWidth < 205 )
windowWidth = 205;
windowHeight = origHeight+IMAGE_TOP+STATUS_HEIGHT+
2*STATUS_BORDER+30;
sprintf(command, "wm geometry . %dx%d", windowWidth, windowHeight);
Tcl_Eval(interp, command);
ResizeWindow();
Tcl_Eval(interp, "update idletasks");
InitXImage();
UpdateStatusBar(oldBytesRead);
ShowFrameInfo();
if ( ! inPlayLoop )
RefreshCurrentImage();
return TCL_OK;
}
int DoubleSizeC(nulldata, interp, argc, argv)
ClientData nulldata;
Tcl_Interp *interp;
int argc;
char **argv;
{
char command[256];
extern int origWidth, origHeight;
extern int windowWidth, windowHeight;
extern int oldBytesRead;
extern int ditherType;
#ifdef BLEAH
ditherType = Twox2_DITHER;
SetUpPlayFrame();
#endif
windowWidth = 2*origWidth+2*IMAGE_LEFT;
if ( windowWidth < 205 )
windowWidth = 205;
windowHeight = 2*origHeight+IMAGE_TOP+STATUS_HEIGHT+
2*STATUS_BORDER+30;
sprintf(command, "wm geometry . %dx%d", windowWidth, windowHeight);
Tcl_Eval(interp, command);
ResizeWindow();
Tcl_Eval(interp, "update idletasks");
InitXImage();
UpdateStatusBar(oldBytesRead);
ShowFrameInfo();
if ( ! inPlayLoop )
RefreshCurrentImage();
return TCL_OK;
}
int ToggleLoopC(nulldata, interp, argc, argv)
ClientData nulldata;
Tcl_Interp *interp;
int argc;
char **argv;
{
extern int loopFlag;
if ( argv[1][0] == '1' )
loopFlag = TRUE;
else
loopFlag = FALSE;
return TCL_OK;
}
int SetTitleC (nulldata, interp, argc, argv)
ClientData nulldata;
Tcl_Interp *interp;
int argc;
char **argv;
{
char command[256];
int height, width;
extern int firstTimePlayed;
extern int first;
int i;
firstTimePlayed = 1;
first = 1;
assert( argc == 2 );
strcpy( title, argv[1]);
if ( title[0] == '/' )
sprintf(command, "wm title . \"%s (%s)\"", strrchr(title, '/')+1, ditherName);
else
sprintf(command, "wm title . \"%s (%s)\"", title, ditherName);
Tcl_Eval(interp, command);
Tcl_Eval(interp, "update");
Tcl_Eval(interp, "ClearState");
displayTime = 0.0;
resetPlayWindow();
if (i = setjmp(env2)) {
if ( i == 2 ) {
Tcl_Eval( interp, "AnnounceError \"Unexpected read error\"" );
} else if (i == 3) {
Tcl_Eval( interp,
"AnnounceError \"Improper or missing sequence end code.\"");
}
if (theStream != NULL) {
DestroyVidStream( &theStream );
theStream = (VidStream *)NULL;
}
Tcl_Eval( interp, "set videoLoaded 0" );
return TCL_OK;
}
playframe(title, IMAGE_LEFT, IMAGE_TOP, &width, &height, TRUE);
sprintf(command, "changeWorkDir %s", title);
Tcl_Eval(interp, command);
sprintf(command, "set mpegWidth %d", theStream->h_size);
Tcl_Eval(interp, command);
sprintf(command, "set mpegHeight %d", theStream->v_size);
Tcl_Eval(interp, command);
{
int num_h_mb, num_v_mb;
num_h_mb = theStream->h_size / 16;
if ((theStream->h_size % 16) != 0)
num_h_mb++;
num_v_mb = theStream->v_size / 16;
if ((theStream->v_size % 16) != 0)
num_v_mb++;
sprintf(command, ".infowin.mvFrame.mvCanvas configure -width %d -height %d",
num_h_mb * 24 + 2,
num_v_mb * 24 + 2);
Tcl_Eval(interp, command);
}
return TCL_OK;
}
int RewindC(nulldata, interp, argc, argv)
ClientData nulldata;
Tcl_Interp *interp;
int argc;
char **argv;
{
int height, width;
/* If there's previous frames to restore, do it and play one frame */
if (restoreVidStream( theStream ))
{
/* Clear the gauges */
Tcl_Eval( interp, "ClearGauges\n");
/* Play one frame */
Tcl_Eval( interp, "NextFrame\n" );
}
justRewound = TRUE;
return TCL_OK;
}
int StopC(nulldata, interp, argc, argv)
ClientData nulldata;
Tcl_Interp *interp;
int argc;
char **argv;
{
if ( inPlayLoop ) {
globalCommand = STOP_COMMAND;
}
/* otherwise, ignore */
return TCL_OK;
}
int PlayPauseC(nulldata, interp, argc, argv)
ClientData nulldata;
Tcl_Interp *interp;
int argc;
char **argv;
{
int width, height;
extern double stoppedTime;
int stillPlaying = TRUE;
inPlayLoop = TRUE;
stoppedTime += (ReadSysClock()-stopStartTime);
globalCommand = PLAY_COMMAND;
ContinuePlay(FALSE);
globalCommand = STOP_COMMAND;
inPlayLoop = FALSE;
stopStartTime = ReadSysClock();
justRewound = FALSE;
return TCL_OK;
}
#ifndef NO_CHANGE
int NextFrameC(nulldata, interp, argc, argv)
ClientData nulldata;
Tcl_Interp *interp;
int argc;
char **argv;
{
extern double stoppedTime;
extern int totNumFrames;
int width, height, lastNumFrames;
char command[256];
if ( inPlayLoop ) {
globalCommand = NEXT_COMMAND;
} else {
if ( movieOpen ) {
stoppedTime += (ReadSysClock() - stopStartTime);
lastNumFrames = totNumFrames;
while ( mpegVidRsrc(0, theStream) ) {
if (lastNumFrames != totNumFrames)
break;
}
stopStartTime = ReadSysClock();
}
}
sprintf(command, "update idletasks");
Tcl_Eval(interp, command);
justRewound = FALSE;
return(TCL_OK);
}
#endif
int SetFPSC(nulldata, interp, argc, argv)
ClientData nulldata;
Tcl_Interp *interp;
int argc;
char **argv;
{
extern double displayTime;
int newFPS;
newFPS = atoi(argv[1]);
if ( newFPS == 0 )
{
displayTime = 0.0;
justShowOne = TRUE;
}
else
{
displayTime = 1.0/(float)newFPS;
justShowOne = FALSE;
}
realFPS = (float)newFPS;
return TCL_OK;
}
int SetPercentC(nulldata, interp, argc, argv)
ClientData nulldata;
Tcl_Interp *interp;
int argc;
char **argv;
{
int newPercent;
newPercent = atoi(argv[1]);
percentPlay = (float)newPercent*0.01;
return TCL_OK;
}
int NewShow(nulldata, interp, argc, argv)
ClientData nulldata;
Tcl_Interp *interp;
int argc;
char **argv;
{
char command[512];
sprintf(command, "%s %s %s &", program, title, argv[1]);
system(command);
return TCL_OK;
}
static void BrowserRedrawHandler(clientData, eventPtr)
ClientData clientData; /* Information about window. */
XEvent *eventPtr; /* Information about event. */
{
extern int oldBytesRead;
extern int windowReady;
extern int windowHeight, windowWidth;
extern int handlingError;
XExposeEvent *exposeEvent;
int height, width;
if ( handlingError )
return;
exposeEvent = &(eventPtr->xexpose);
/* should really keep track of redraw events and do at once */
if ( exposeEvent->count != 0 )
return;
if ( ! windowReady )
return;
height = Tk_Height(w);
width = Tk_Width(w);
if ( (height != windowHeight) || (width != windowWidth) )
{
windowHeight = height;
windowWidth = width;
ResizeWindow();
Tcl_Eval(interp, "update idletasks");
InitXImage();
}
else
{
/* reprint Frame: and status bar */
ShowFPS();
ShowStatusOutline();
}
UpdateStatusBar(oldBytesRead);
ShowFrameInfo();
if ( ! inPlayLoop )
RefreshCurrentImage();
}
/*
* Procedure to map initial window. This is invoked as a do-when-idle
* handler. Wait for all other when-idle handlers to be processed
* before mapping the window, so that the window's correct geometry
* has been determined.
*/
static void DelayedMap(clientData)
ClientData clientData; /* Not used. */
{
while (Tk_DoOneEvent(1) != 0) {
/* Empty loop body. */
}
if (w == NULL) {
return;
}
Tk_MapWindow(w);
}
static void
db_usage() {
fprintf (stderr, "\n\nUsage:\n");
fprintf (stderr, "mpeg_bits ?-dither <dither name>? ?<filename>?\n");
fprintf (stderr, "<dither name> is any of the following:\n");
fprintf (stderr, "\thybrid, hybrid2, fs4, fs2, fs2fast, ordered, ordered2, mbordered, mono, threshold.\n");
fprintf (stderr, "<filename> is the name of an MPEG file.\n");
fprintf (stderr, "No filename allows the user to select a file through\n");
fprintf (stderr, "the file dialog, and no dither name defaults to ordered2.\n");
exit(0);
}
/************************************************************************/
int main(argc, argv)
int argc;
char **argv;
{
char *args, *p, *msg;
char buf[20];
char command[256];
char editsFileName[256];
int result;
Tk_3DBorder border;
struct stat stbuf;
extern int ditherType;
int width, height;
int i, ditherGiven, titleGiven, editsFileGiven;
strcpy(program, argv[0]);
printf("\nmpeg_bits (version 1.0b)\n\n");
/* tclInit(); */
interp = Tcl_CreateInterp();
#ifdef TCL_MEM_DEBUG
Tcl_InitMemory(interp);
#endif
ditherGiven = 0;
titleGiven = 0;
editsFileGiven = 0;
for ( i = 1; i < argc; i++) {
if (!strcmp( argv[i], "-edits")) {
if (++i < argc) {
editsFileGiven = 1;
strcpy( editsFileName, argv[i]);
} else {
fprintf( stderr, "Must include edits file name when using the -edits flag.");
db_usage();
}
} else if (!strcmp( argv[i], "-dither")) {
if ( ++i < argc ) {
ditherGiven = 1;
strcpy( ditherName, argv[i]);
if (strcmp(ditherName, "hybrid") == 0) {
ditherType = HYBRID_DITHER;
} else if (strcmp(ditherName, "hybrid2") == 0) {
ditherType = HYBRID2_DITHER;
} else if (strcmp(ditherName, "fs4") == 0) {
ditherType = FS4_DITHER;
} else if (strcmp(ditherName, "fs2") == 0) {
ditherType = FS2_DITHER;
} else if (strcmp(ditherName, "fs2fast") == 0) {
ditherType = FS2FAST_DITHER;
#ifdef NO_CHANGE
} else if (strcmp(ditherName, "gray") == 0) {
ditherType = GRAY_DITHER;
} else if (strcmp(ditherName, "2x2") == 0) {
ditherType = Twox2_DITHER;
} else if (strcmp(ditherName, "color") == 0) {
ditherType = FULL_COLOR_DITHER;
} else if (strcmp(ditherName, "none") == 0) {
ditherType = NO_DITHER;
#endif
} else if (strcmp(ditherName, "ordered") == 0) {
ditherType = ORDERED_DITHER;
} else if (strcmp(ditherName, "ordered2") == 0) {
ditherType = ORDERED2_DITHER;
} else if (strcmp(ditherName, "mbordered") == 0) {
ditherType = MBORDERED_DITHER;
#ifdef NO_CHANGE
} else if (strcmp(ditherName, "mono") == 0) {
ditherType = MONO_DITHER;
} else if (strcmp(ditherName, "threshold") == 0) {
ditherType = MONO_THRESHOLD;
#endif
} else {
fprintf( stderr, "Illegal dither option.");
db_usage();
}
} else {
fprintf( stderr, "Must include dither selection when using -dither flag.");
db_usage();
}
} else if ( i = argc-1 ) {
titleGiven = 1;
strcpy(title, argv[i]);
} else {
fprintf( stderr, "Bad argument: %s.", argv[i]);
db_usage();
}
}
if (!titleGiven && editsFileGiven) {
printf("Edits file %s being ignored because no stream title was supplied\n", editsFileName);
editsFileGiven = 0;
}
if (!ditherGiven) {
ditherType = ORDERED2_DITHER;
sprintf(ditherName, "ordered2");
}
if (titleGiven) {
if ( stat( title, &stbuf ) == -1 ) {
printf( "Can't find file \"%s\": starting program with no video loaded\n",
title);
sprintf( title, "*no video loaded*");;
titleGiven = 0;
}
} else {
sprintf( title, "*no video loaded*");;
}
argv[1] = "-f";
{
char *show_tcl = (char *) malloc((unsigned int) 100);
sprintf(show_tcl, "%s/show.tcl", BITS_DIR);
argv[2] = show_tcl;
}
argc = 3;
if (Tk_ParseArgv(interp, (Tk_Window) NULL, &argc, argv, argTable, 0)
!= TCL_OK) {
fprintf(stderr, "%s\n", interp->result);
exit(1);
}
if (name == NULL) {
if (fileName != NULL) {
p = fileName;
} else {
p = argv[0];
}
name = strrchr(p, '/');
if (name != NULL) {
name++;
} else {
name = p;
}
}
if ( (w = Tk_CreateMainWindow(interp, displayName, name, "")) == NULL )
{
fprintf(stderr, "%s\n", interp->result);
exit(1);
}
Tk_SetClass(w, "Tk");
Tk_CreateEventHandler(w, StructureNotifyMask, StructureProc,
(ClientData) NULL);
Tk_DoWhenIdle(DelayedMap, (ClientData) NULL);
Tk_CreateEventHandler(w, /* mask */ ExposureMask,
BrowserRedrawHandler, (ClientData) NULL);
tty = isatty(0);
Tcl_SetVar(interp, "tcl_interactive", "0", TCL_GLOBAL_ONLY);
if (Tcl_AppInit(interp) != TCL_OK) {
fprintf(stderr, "Tcl_AppInit failed: %s\n", interp->result);
}
args = Tcl_Merge(argc-1, argv+1);
Tcl_SetVar(interp, "argv", args, TCL_GLOBAL_ONLY);
ckfree(args);
sprintf(buf, "%d", argc-1);
Tcl_SetVar(interp, "argc", buf, TCL_GLOBAL_ONLY);
Tcl_SetVar(interp, "prompt", PROMPT, TCL_GLOBAL_ONLY);
if (synchronize) {
XSynchronize(Tk_Display(w), True);
}
Tk_GeometryRequest(w, 200, 200);
#if (TK_MAJOR_VERSION>=4)
border = NULL; /* Someone running 4.0 can fix this... */
#else
border = Tk_Get3DBorder(interp, w, None, "#4eee94");
#endif
if (border == NULL) {
Tcl_SetResult(interp, (char *) NULL, TCL_STATIC);
Tk_SetWindowBackground(w, WhitePixelOfScreen(Tk_Screen(w)));
} else {
Tk_SetBackgroundFromBorder(w, border);
}
XSetForeground(Tk_Display(w), DefaultGCOfScreen(Tk_Screen(w)),
BlackPixelOfScreen(Tk_Screen(w)));
Tcl_CreateCommand (interp, "OrigSize", OrigSizeC, (ClientData) 0,
(void (*) ()) NULL);
Tcl_CreateCommand (interp, "DoubleSize", DoubleSizeC, (ClientData) 0,
(void (*) ()) NULL);
Tcl_CreateCommand (interp, "ToggleLoop", ToggleLoopC, (ClientData) 0,
(void (*) ()) NULL);
Tcl_CreateCommand (interp, "SetTitle", SetTitleC, (ClientData) 0,
(void (*) ()) NULL);
Tcl_CreateCommand (interp, "Rewind", RewindC, (ClientData) 0,
(void (*) ()) NULL);
Tcl_CreateCommand (interp, "Stop", StopC, (ClientData) 0,
(void (*) ()) NULL);
Tcl_CreateCommand (interp, "PlayPause", PlayPauseC, (ClientData) 0,
(void (*) ()) NULL);
Tcl_CreateCommand (interp, "SetFPS", SetFPSC, (ClientData) 0,
(void (*) ()) NULL);
Tcl_CreateCommand (interp, "SetPercent", SetPercentC, (ClientData) 0,
(void (*) ()) NULL);
Tcl_CreateCommand (interp, "newshow", NewShow, (ClientData) 0,
(void (*) ()) NULL);
#ifndef NO_CHANGE
Tcl_CreateCommand (interp, "NextFrame", NextFrameC, (ClientData) 0,
(void (*) ()) NULL);
#endif
if (geometry != NULL) {
Tcl_SetVar(interp, "geometry", geometry, TCL_GLOBAL_ONLY);
}
#ifdef BLEAH
result = Tcl_Eval(interp, "source $tk_library/menu.tcl");
if (result != TCL_OK) {
goto error;
}
result = Tcl_Eval(interp, initCmd);
if (result != TCL_OK) {
goto error;
}
#endif
if (fileName != NULL) {
result = Tcl_VarEval(interp, "source ", fileName, (char *) NULL);
if (result != TCL_OK) {
goto error;
}
tty = 0;
} else {
tty = isatty(0);
#ifdef BLEAH
Tk_CreateFileHandler(0, TK_READABLE, StdinProc, (ClientData) 0);
if (tty) {
printf(Tcl_GetVar (interp, "prompt", TCL_GLOBAL_ONLY));
}
#endif
}
fflush(stdout);
#ifdef BLEAH
buffer = Tcl_CreateCmdBuf();
#endif
#ifdef LINUX
(void) Tcl_Eval(interp, "source /var/X11/lib/X11/tk/tk.tcl");
(void) Tcl_Eval(interp, "source /var/X11/lib/X11/tk/button.tcl");
(void) Tcl_Eval(interp, "source /var/X11/lib/X11/tk/tkerror.tcl");
#else
(void) Tcl_Eval(interp, "source /usr/cluster/lib/tk/tk.tcl");
(void) Tcl_Eval(interp, "source /usr/cluster/lib/tk/button.tcl");
(void) Tcl_Eval(interp, "source /usr/cluster/lib/tk/tkerror.tcl");
#endif
sprintf(command, "set libDir %s\n", BITS_DIR);
Tcl_Eval(interp, command);
Tcl_Eval(interp, "Init_Dirs\n");
Tcl_Eval(interp, "Init_Win\n");
(void) Tcl_Eval(interp, "update");
winID = Tk_WindowId(w);
winDisplay = Tk_Display(w);
gc = XCreateGC(winDisplay, winID, 0, 0);
SetUpPlayFrame(winDisplay, gc, winID);
if ( title[0] == '/' )
sprintf(command, "wm title . \"%s (%s)\"",
strrchr(title, '/')+1,
ditherName);
else
sprintf(command, "wm title . \"%s (%s)\"",
title,
ditherName);
Tcl_Eval(interp, command);
Tcl_Eval(interp, "update");
globalCommand = STOP_COMMAND;
if (i = setjmp(env2)) {
if ( i == 2 ) {
Tcl_Eval( interp, "AnnounceError \"Unexpected read error\"" );
} else if (i == 3) {
Tcl_Eval( interp,
"AnnounceError \"Improper or missing sequence end code.\"");
}
if (theStream != NULL) {
DestroyVidStream( &theStream );
theStream = (VidStream *)NULL;
}
titleGiven = 0;
}
if (titleGiven) {
playframe(title, IMAGE_LEFT, IMAGE_TOP, &width, &height, TRUE);
sprintf( command, "changeWorkDir %s", title );
Tcl_Eval(interp, command);
sprintf(command, "set mpegWidth %d", theStream->h_size);
Tcl_Eval(interp, command);
sprintf(command, "set mpegHeight %d", theStream->v_size);
Tcl_Eval(interp, command);
{
int num_h_mb, num_v_mb;
num_h_mb = theStream->h_size / 16;
if ((theStream->h_size % 16) != 0)
num_h_mb++;
num_v_mb = theStream->v_size / 16;
if ((theStream->v_size % 16) != 0)
num_v_mb++;
sprintf(command,
".infowin.mvFrame.mvCanvas configure -width %d -height %d",
num_h_mb * 24 + 2,
num_v_mb * 24 + 2);
Tcl_Eval(interp, command);
if (editsFileGiven) {
sprintf( command, "loadEditList [string trim %s]\n", editsFileName);
Tcl_Eval(interp, command);
}
}
} else {
Tcl_Eval( interp, "noVideoDisable" );
Tcl_Eval( interp, "set videoLoaded 0" );
}
Tk_MainLoop();
Tcl_DeleteInterp(interp);
#ifdef BLEAH
Tcl_DeleteCmdBuf(buffer);
#endif
exit(0);
error:
msg = Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY);
if (msg == NULL) {
msg = interp->result;
}
fprintf(stderr, "%s\n", msg);
#ifdef BLEAH
Tcl_Eval(interp, "destroy .", 0, (char **) NULL);
#endif
exit(1);
return 0;
}
void PlayLoop()
{
int stillPlaying = TRUE;
int height, width;
inPlayLoop = TRUE;
while ( stillPlaying )
{
playframe(title, IMAGE_LEFT, IMAGE_TOP, &width, &height, FALSE);
switch(globalCommand)
{
case NO_COMMAND:
stillPlaying = FALSE;
break;
case REWIND_COMMAND: /* continue playing */
break;
case STOP_COMMAND:
fclose(input);
playframe(title, IMAGE_LEFT, IMAGE_TOP, &width, &height, TRUE);
stillPlaying = FALSE;
break;
case PLAY_COMMAND:
stillPlaying = FALSE;
break;
#ifndef NO_CHANGE
case NEXT_COMMAND:
stillPlaying = FALSE;
break;
#endif
}
globalCommand = NO_COMMAND;
}
inPlayLoop = FALSE;
stopStartTime = ReadSysClock();
}
void ContinuePlayLoop()
{
extern double stoppedTime;
int stillPlaying = TRUE;
int height, width;
inPlayLoop = TRUE;
stoppedTime += (ReadSysClock()-stopStartTime);
while ( stillPlaying )
{
ContinuePlay(FALSE);
switch(globalCommand)
{
case NO_COMMAND:
stillPlaying = FALSE;
break;
case REWIND_COMMAND: /* continue playing */
stillPlaying = FALSE;
PlayLoop();
break;
case STOP_COMMAND:
fclose(input);
playframe(title, IMAGE_LEFT, IMAGE_TOP, &width, &height, TRUE);
stillPlaying = FALSE;
break;
case PLAY_COMMAND:
stillPlaying = FALSE;
break;
#ifndef NO_CHANGE
case NEXT_COMMAND:
stillPlaying = FALSE;
break;
#endif
}
globalCommand = NO_COMMAND;
}
inPlayLoop = FALSE;
stopStartTime = ReadSysClock();
}
/*
*----------------------------------------------------------------------
*
* Tcl_AppInit --
*
* This procedure performs application-specific initialization.
* Most applications, especially those that incorporate additional
* packages, will have their own version of this procedure.
*
* Results:
* Returns a standard Tcl completion code, and leaves an error
* message in interp->result if an error occurs.
*
* Side effects:
* Depends on the startup script.
*
*----------------------------------------------------------------------
*/
int
Tcl_AppInit(interp)
Tcl_Interp *interp;
{
Tk_Window main;
main = Tk_MainWindow(interp);
if (main == NULL) {
return TCL_ERROR;
}
/*
* Call the init procedures for included packages. Each call should
* look like this:
*
* if (Mod_Init(interp) == TCL_ERROR) {
* return TCL_ERROR;
* }
*
* where "Mod" is the name of the module.
*/
if (Tcl_Init(interp) == TCL_ERROR) {
return TCL_ERROR;
}
if (Tk_Init(interp) == TCL_ERROR) {
return TCL_ERROR;
}
return TCL_OK;
} /* Tcl_AppInit */
|