home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / maestro / source / videofrm / editlist.c next >
Encoding:
C/C++ Source or Header  |  1993-06-15  |  17.4 KB  |  434 lines

  1. /*
  2.  * Copyright (c) 1992 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software and 
  5.  * its documentation for any purpose is hereby granted without fee, provided
  6.  * that (i) the above copyright notices and this permission notice appear in
  7.  * all copies of the software and related documentation, and (ii) the name
  8.  * Stanford may not be used in any advertising or publicity relating to
  9.  * the software without the specific, prior written permission of
  10.  * Stanford.
  11.  * 
  12.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  13.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  14.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  15.  *
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
  17.  * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES
  18.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT
  19.  * ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY,
  20.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21.  * SOFTWARE.
  22.  */
  23.  
  24. /* $Header: /Source/Media/drapeau/VideoFrame/RCS/editList.c,v 1.1 92/07/14 14:42:20 drapeau Exp $ */
  25. /* $Log:    editList.c,v $
  26.  * Revision 1.1  92/07/14  14:42:20  drapeau
  27.  * Initial revision
  28.  *  */
  29.  
  30. #include "VideoFrame.h"
  31. static char editListRcsid[] = "$Header: /Source/Media/drapeau/VideoFrame/RCS/editList.c,v 1.1 92/07/14 14:42:20 drapeau Exp $";
  32.  
  33. void    InitEditList()
  34. {
  35.   int    i=0;
  36.   
  37.   for (i=0; i < MaxNumberEditListItems; i++)
  38.   {
  39.     editList.item[i].input1.shown = False;
  40.     editList.item[i].input1.cropped = False;
  41.     editList.item[i].input1.aspectRatio = Any;
  42.     editList.item[i].input1.brightness = 128;
  43.     editList.item[i].input1.contrast = 128;
  44.     editList.item[i].input1.saturation = 128;
  45.     editList.item[i].input1.hue = 128;
  46.     editList.item[i].input1.width = 640;
  47.     editList.item[i].input1.height = 480;
  48.     editList.item[i].input1.x = 0;
  49.     editList.item[i].input1.y = 0;
  50.     
  51.     editList.item[i].input2.shown = False;
  52.     editList.item[i].input2.cropped = False;
  53.     editList.item[i].input2.aspectRatio = Any;
  54.     editList.item[i].input2.brightness = 128;
  55.     editList.item[i].input2.contrast = 128;
  56.     editList.item[i].input2.saturation = 128;
  57.     editList.item[i].input2.hue = 128;
  58.     editList.item[i].input2.width = 640;
  59.     editList.item[i].input2.height = 480;
  60.     editList.item[i].input2.x = 0;
  61.     editList.item[i].input2.y = 0;
  62.   }                                    /* end for */
  63. }                                    /* end function InitEditList */
  64.  
  65.  
  66.  
  67. /*
  68.  * This function loads a file into the edit list, assuming there 
  69.  * are no errors in opening the file.
  70.  */
  71. int OpenEditList(char* filename, int id)
  72. {
  73.   FILE*    fp;
  74.   char    header[LabelLength + 16];
  75.   char    theString[LabelLength];
  76.   int    i;
  77.   int    dummy;
  78.   
  79.   if (strcmp(filename, "Untitled") == 0)                /* Check if filename is 'untitled' (unacceptable) */
  80.   {
  81.     AlertMessage("'Untitled' is not an acceptable filename.", "please type in a new one.");
  82.     return(-1);
  83.   }
  84.   if (unsavedChanges == True)                        /* Check if there are unsaved changes */
  85.   {
  86.     return(0);
  87.   }
  88.   fp = fopen(filename, "r");                
  89.   fgets(header, 32, fp);
  90.   if (strcmp(header, "#VideoFrame Document#\n") != 0)            /* Check if the file is a VideoFrame document */
  91.   {
  92.     AlertMessage("This is not a VideoFrame document.", "Please try another file");
  93.     fclose(fp);
  94.     return(-1);
  95.   }
  96.   fscanf(fp, "#Number of Edits : %d\n", &(editList.numEdits));
  97.   fscanf(fp, "\n");
  98.   for (i=0; i < editList.numEdits; i++)                    /* Load in one edit at a time */
  99.   {
  100.     fscanf(fp, "\n\n\n");
  101.     fscanf(fp, "#Edit Number : %d\n", &dummy);
  102.     fgets(header, (LabelLength + 16), fp);                /* Scan the label line for this edit */
  103.     strncpy(editList.item[i].label, &header[8], LabelLength-8);
  104.     if (strlen(editList.item[i].label) < (LabelLength - 8))        /* Remove newline character for label if necessary */
  105.       editList.item[i].label[strlen(editList.item[i].label) -1] = '\0';
  106.     fscanf(fp, "Input1 Shown : %s\n", header);
  107.     if (strcmp(header, "Yes") == 0)
  108.       editList.item[i].input1.shown = True;
  109.     else
  110.       editList.item[i].input1.shown = False;
  111.     fscanf(fp, "Input1 Crop or Squeeze : %s\n", header);
  112.     if (strcmp(header, "Crop") == 0)
  113.       editList.item[i].input1.cropped = True;
  114.     else
  115.       editList.item[i].input1.cropped = False;
  116.     fscanf(fp, "Input1 Aspect Ratio : %s\n", header);
  117.     if (strcmp(header, "Any") == 0)
  118.       editList.item[i].input1.aspectRatio = Any;
  119.     else
  120.       editList.item[i].input1.aspectRatio = Fixed;
  121.     fscanf(fp, "Input1 Brightness : %d\n", &(editList.item[i].input1.brightness));
  122.     fscanf(fp, "Input1 Contrast : %d\n", &(editList.item[i].input1.contrast));
  123.     fscanf(fp, "Input1 Saturation : %d\n", &(editList.item[i].input1.saturation));
  124.     fscanf(fp, "Input1 Hue : %d\n", &(editList.item[i].input1.hue));
  125.     fscanf(fp, "Input1 Width : %d\n", &(editList.item[i].input1.width));
  126.     fscanf(fp, "Input1 Height : %d\n", &(editList.item[i].input1.height));
  127.     fscanf(fp, "Input1 X : %d\n", &(editList.item[i].input1.x));
  128.     fscanf(fp, "Input1 Y : %d\n", &(editList.item[i].input1.y));
  129.     fscanf(fp, "\n");
  130.     
  131.     fscanf(fp, "Input2 Shown : %s\n", header);
  132.     if (strcmp(header, "Yes") == 0)
  133.       editList.item[i].input2.shown = True;
  134.     else
  135.       editList.item[i].input2.shown = False;
  136.     fscanf(fp, "Input2 Crop or Squeeze : %s\n", header);
  137.     if (strcmp(header, "Crop") == 0)
  138.       editList.item[i].input2.cropped = True;
  139.     else
  140.       editList.item[i].input2.cropped = False;
  141.     fscanf(fp, "Input2 Aspect Ratio : %s\n", header);
  142.     if (strcmp(header, "Any") == 0)
  143.       editList.item[i].input2.aspectRatio = Any;
  144.     else
  145.       editList.item[i].input2.aspectRatio = Fixed;
  146.     fscanf(fp, "Input2 Brightness : %d\n", &(editList.item[i].input2.brightness));
  147.     fscanf(fp, "Input2 Contrast : %d\n", &(editList.item[i].input2.contrast));
  148.     fscanf(fp, "Input2 Saturation : %d\n", &(editList.item[i].input2.saturation));
  149.     fscanf(fp, "Input2 Hue : %d\n", &(editList.item[i].input2.hue));
  150.     fscanf(fp, "Input2 Width : %d\n", &(editList.item[i].input2.width));
  151.     fscanf(fp, "Input2 Height : %d\n", &(editList.item[i].input2.height));
  152.     fscanf(fp, "Input2 X : %d\n", &(editList.item[i].input2.x));
  153.     fscanf(fp, "Input2 Y : %d\n", &(editList.item[i].input2.y));
  154.   }                                    /* end for... */
  155.   fclose (fp);
  156.   if (currentEdit != NoCurrentEdit)                    /* Deselect any currently selected entry */
  157.   {
  158.     xv_set(VideoFrame_mainWindow->editList,
  159.        PANEL_LIST_SELECT, currentEdit, FALSE,
  160.        NULL);
  161.   }
  162.   EmptyList();                                /* Erase old contents of the scrolled list */
  163.   for (i=0; i < editList.numEdits; i++)                    /* Replace the old strings by the new ones */
  164.   {
  165.     FormatEntry(i, &(editList.item[i]), theString);
  166.     xv_set (VideoFrame_mainWindow->editList,
  167.         PANEL_LIST_INSERT, i,
  168.         PANEL_LIST_STRING, i, theString,
  169.         NULL);
  170.   }
  171.   unsavedChanges = False;
  172.   currentEdit = NoCurrentEdit;
  173.   numEdits = editList.numEdits;
  174.   strcpy(editListFileName, filename);
  175.   xv_set(VideoFrame_mainWindow->currentSelectionMessage,
  176.      PANEL_LABEL_STRING, "Current Selection : None", NULL);
  177.   xv_set(VideoFrame_mainWindow->modifyButton, PANEL_INACTIVE, TRUE, NULL); /* Set the modify, delete buttons to inactive */
  178.   xv_set(VideoFrame_mainWindow->deleteButton, PANEL_INACTIVE, TRUE, NULL);
  179.   UpdateHeader();                            /* Print new document name */
  180.   return(0);
  181. }                                    /* end function OpenEditList */
  182.  
  183.  
  184.  
  185.  
  186. /*
  187.  * This function saves the current edit list into the file
  188.  * specified in the filename passed in as argument.  If the file
  189.  * already exists, the user is warned and given the choice
  190.  * to proceed or abort.
  191.  */
  192. int SaveEditList(char *filename, int id)
  193. {
  194.   FILE*    fp = (FILE*)NULL;
  195.   int    i;
  196.   
  197.   if (strcmp(filename, "Untitled") == 0)                /* Check if filename is 'untitled' (unacceptable) */
  198.   {
  199.     AlertMessage("'untitled' is not an acceptable filename.",
  200.          "please type in a new one.");
  201.     return(-1);
  202.   }
  203.   fp = fopen(filename, "w");                        /* Try to open the file for writing */
  204.   if (fp == (FILE*)NULL)                        /* Did an error occur? */
  205.   {                                    /* Yes, return an error and exit this function */
  206.     return(-1);
  207.   }
  208.   fprintf(fp, "#VideoFrame Document#\n");                /* Write the document's header */
  209.   fprintf(fp, "#Number of Edits : %d\n", numEdits);
  210.   for (i=0; i < numEdits; i++) 
  211.   {
  212.     fprintf(fp, "\n\n\n");
  213.     fprintf(fp, "#Edit Number :\t\t\t%d\n", i + 1);
  214.     fprintf(fp, "Label :\t\t\t\t%s\n", editList.item[i].label);
  215.     if (editList.item[i].input1.shown == True)
  216.       fprintf(fp, "Input1 Shown :\t\t\tYes\n");
  217.     else
  218.       fprintf(fp, "Input1 Shown :\t\t\tNo\n");
  219.     if (editList.item[i].input1.cropped == True)
  220.       fprintf(fp, "Input1 Crop or Squeeze :\tCrop\n");
  221.     else
  222.       fprintf(fp, "Input1 Crop or Squeeze :\tSqueeze\n");
  223.     if (editList.item[i].input1.aspectRatio == Any)
  224.       fprintf(fp, "Input1 Aspect Ratio :\t\tAny\n");
  225.     else
  226.       fprintf(fp, "Input1 Aspect Ratio :\t\t4-to-3\n");
  227.     fprintf(fp, "Input1 Brightness :\t\t%d\n", editList.item[i].input1.brightness);
  228.     fprintf(fp, "Input1 Contrast :\t\t%d\n", editList.item[i].input1.contrast);
  229.     fprintf(fp, "Input1 Saturation :\t\t%d\n", editList.item[i].input1.saturation);
  230.     fprintf(fp, "Input1 Hue :\t\t\t%d\n", editList.item[i].input1.hue);
  231.     fprintf(fp, "Input1 Width :\t\t\t%d\n", editList.item[i].input1.width);
  232.     fprintf(fp, "Input1 Height :\t\t\t%d\n", editList.item[i].input1.height);
  233.     fprintf(fp, "Input1 X :\t\t\t%d\n", editList.item[i].input1.x);
  234.     fprintf(fp, "Input1 Y :\t\t\t%d\n", editList.item[i].input1.y);
  235.     fprintf(fp, "\n");
  236.     if (editList.item[i].input2.shown == True)
  237.       fprintf(fp, "Input2 Shown :\t\t\tYes\n");
  238.     else
  239.       fprintf(fp, "Input2 Shown :\t\t\tNo\n");
  240.     if (editList.item[i].input2.cropped == True)
  241.       fprintf(fp, "Input2 Crop or Squeeze :\tCrop\n");
  242.     else
  243.       fprintf(fp, "Input2 Crop or Squeeze :\tSqueeze\n");
  244.     if (editList.item[i].input2.aspectRatio == Any)
  245.       fprintf(fp, "Input2 Aspect Ratio :\t\tAny\n");
  246.     else
  247.       fprintf(fp, "Input2 Aspect Ratio :\t\t4-to-3\n");
  248.     fprintf(fp, "Input2 Brightness :\t\t%d\n", editList.item[i].input2.brightness);
  249.     fprintf(fp, "Input2 Contrast :\t\t%d\n", editList.item[i].input2.contrast);
  250.     fprintf(fp, "Input2 Saturation :\t\t%d\n", editList.item[i].input2.saturation);
  251.     fprintf(fp, "Input2 Hue :\t\t\t%d\n", editList.item[i].input2.hue);
  252.     fprintf(fp, "Input2 Width :\t\t\t%d\n", editList.item[i].input2.width);
  253.     fprintf(fp, "Input2 Height :\t\t\t%d\n", editList.item[i].input2.height);
  254.     fprintf(fp, "Input2 X :\t\t\t%d\n", editList.item[i].input2.x);
  255.     fprintf(fp, "Input2 Y :\t\t\t%d\n", editList.item[i].input2.y);
  256.   }
  257.   fclose (fp);
  258.   unsavedChanges = False;
  259.   strcpy(editListFileName, filename);
  260.   UpdateHeader();                            /* Print new document name */
  261.   return(0);
  262. }                                    /* end function SaveEditList */
  263.  
  264.  
  265.  
  266. void LoadCurrentSelection(int row)
  267. {
  268.   Rect    tempRect;
  269.   
  270.   currentEdit = row;
  271.   xv_set(VideoFrame_mainWindow->labelField, PANEL_VALUE,        /* Print the label for this edit in the textfield */
  272.      editList.item[row].label, NULL);
  273.   currentSelection.input1.shown = editList.item[row].input1.shown;
  274.   if (currentSelection.input1.shown == True)
  275.   {
  276.     ShowWindow((Panel_item)VideoFrame_mainWindow->input1ShownChoice,
  277.            0, (Event*)NULL);
  278.     xv_set(VideoFrame_mainWindow->input1ShownChoice,
  279.        PANEL_VALUE, 0, NULL);
  280.   }
  281.   else
  282.   {
  283.     HideWindow((Panel_item)VideoFrame_mainWindow->input1ShownChoice,
  284.            0, (Event*)NULL);
  285.     xv_set(VideoFrame_mainWindow->input1ShownChoice,
  286.        PANEL_VALUE, 1, NULL);
  287.   }
  288.   
  289.   currentSelection.input1.cropped = editList.item[row].input1.cropped;
  290.   if (currentSelection.input1.cropped == True)
  291.   {
  292.     CropWindow((Panel_item)VideoFrame_mainWindow->input1CroppedChoice,
  293.            0, (Event*)NULL);
  294.     xv_set(VideoFrame_mainWindow->input1CroppedChoice,
  295.        PANEL_VALUE, 0, NULL);
  296.   }
  297.   else
  298.   {
  299.     SqueezeWindow((Panel_item)VideoFrame_mainWindow->input1CroppedChoice,
  300.           0, (Event*)NULL);
  301.     xv_set(VideoFrame_mainWindow->input1CroppedChoice,
  302.        PANEL_VALUE, 1, NULL);
  303.   }  
  304.   currentSelection.input1.aspectRatio = editList.item[row].input1.aspectRatio;
  305.   if (currentSelection.input1.aspectRatio == Fixed)
  306.   {
  307.     SetAspectAny((Panel_item)VideoFrame_mainWindow->input1AspectChoice,
  308.          0, (Event*)NULL);
  309.     xv_set(VideoFrame_mainWindow->input1AspectChoice,
  310.        PANEL_VALUE, 1, NULL);
  311.   }
  312.   else
  313.   {
  314.     SetAspect4to3((Panel_item)VideoFrame_mainWindow->input1AspectChoice,
  315.           0, (Event*)NULL);
  316.     xv_set(VideoFrame_mainWindow->input1AspectChoice,
  317.        PANEL_VALUE, 0, NULL);
  318.   }  
  319.   currentSelection.input1.brightness = editList.item[row].input1.brightness;
  320.   BrightnessHandler((Panel_item)VideoFrame_mainWindow->input1BrightSlider,
  321.             currentSelection.input1.brightness, (Event*)NULL);
  322.   xv_set(VideoFrame_mainWindow->input1BrightSlider,
  323.      PANEL_VALUE, currentSelection.input1.brightness, NULL);
  324.   
  325.   currentSelection.input1.contrast = editList.item[row].input1.contrast;
  326.   ContrastHandler((Panel_item)VideoFrame_mainWindow->input1ContrastSlider,
  327.           currentSelection.input1.contrast, (Event*)NULL);
  328.   xv_set(VideoFrame_mainWindow->input1ContrastSlider,
  329.      PANEL_VALUE, currentSelection.input1.contrast, NULL);
  330.   
  331.   currentSelection.input1.saturation = editList.item[row].input1.saturation;
  332.   SaturationHandler((Panel_item)VideoFrame_mainWindow->input1SaturationSlider,
  333.             currentSelection.input1.saturation, (Event*)NULL);
  334.   xv_set(VideoFrame_mainWindow->input1SaturationSlider,
  335.      PANEL_VALUE, currentSelection.input1.saturation, NULL);
  336.   
  337.   currentSelection.input1.hue = editList.item[row].input1.hue;
  338.   HueHandler((Panel_item)VideoFrame_mainWindow->input1HueSlider,
  339.          currentSelection.input1.hue, (Event*)NULL);
  340.   xv_set(VideoFrame_mainWindow->input1HueSlider,
  341.      PANEL_VALUE, currentSelection.input1.hue, NULL);
  342.   
  343.   currentSelection.input1.width = editList.item[row].input1.width;
  344.   currentSelection.input1.height = editList.item[row].input1.height;
  345.   currentSelection.input1.x = editList.item[row].input1.x;
  346.   currentSelection.input1.y = editList.item[row].input1.y;
  347.   tempRect.r_left = currentSelection.input1.x;
  348.   tempRect.r_top = currentSelection.input1.y;
  349.   tempRect.r_width = currentSelection.input1.width;
  350.   tempRect.r_height = currentSelection.input1.height;
  351.   frame_set_rect(VideoFrame_inputWindow1->inputWindow1, &tempRect);
  352.   
  353.   currentSelection.input2.shown = editList.item[row].input2.shown;
  354.   if (currentSelection.input2.shown == True)
  355.   {
  356.     ShowWindow((Panel_item)VideoFrame_mainWindow->input2ShownChoice,
  357.            0, (Event*)NULL);
  358.     xv_set(VideoFrame_mainWindow->input2ShownChoice,
  359.        PANEL_VALUE, 0, NULL);
  360.   }
  361.   else
  362.   {
  363.     HideWindow((Panel_item)VideoFrame_mainWindow->input2ShownChoice,
  364.            0, (Event*)NULL);
  365.     xv_set(VideoFrame_mainWindow->input2ShownChoice,
  366.        PANEL_VALUE, 1, NULL);
  367.   }
  368.   
  369.   currentSelection.input2.cropped = editList.item[row].input2.cropped;
  370.   if (currentSelection.input2.cropped == True)
  371.   {
  372.     CropWindow((Panel_item)VideoFrame_mainWindow->input2CroppedChoice,
  373.            0, (Event*)NULL);
  374.     xv_set(VideoFrame_mainWindow->input2CroppedChoice,
  375.        PANEL_VALUE, 0, NULL);
  376.   }
  377.   else
  378.   {
  379.     SqueezeWindow((Panel_item)VideoFrame_mainWindow->input2CroppedChoice,
  380.           0, (Event*)NULL);
  381.     xv_set(VideoFrame_mainWindow->input2CroppedChoice,
  382.        PANEL_VALUE, 1, NULL);
  383.   }  
  384.   currentSelection.input2.aspectRatio = editList.item[row].input2.aspectRatio;
  385.   if (currentSelection.input2.aspectRatio == Fixed)
  386.   {
  387.     SetAspectAny((Panel_item)VideoFrame_mainWindow->input2AspectChoice,
  388.          0, (Event*)NULL);
  389.     xv_set(VideoFrame_mainWindow->input2AspectChoice,
  390.        PANEL_VALUE, 1, NULL);
  391.   }
  392.   else
  393.   {
  394.     SetAspect4to3((Panel_item)VideoFrame_mainWindow->input2AspectChoice,
  395.           0, (Event*)NULL);
  396.     xv_set(VideoFrame_mainWindow->input2AspectChoice,
  397.        PANEL_VALUE, 0, NULL);
  398.   }  
  399.   currentSelection.input2.brightness = editList.item[row].input2.brightness;
  400.   BrightnessHandler((Panel_item)VideoFrame_mainWindow->input2BrightSlider,
  401.             currentSelection.input2.brightness, (Event*)NULL);
  402.   xv_set(VideoFrame_mainWindow->input2BrightSlider,
  403.      PANEL_VALUE, currentSelection.input2.brightness, NULL);
  404.   
  405.   currentSelection.input2.contrast = editList.item[row].input2.contrast;
  406.   ContrastHandler((Panel_item)VideoFrame_mainWindow->input2ContrastSlider,
  407.           currentSelection.input2.contrast, (Event*)NULL);
  408.   xv_set(VideoFrame_mainWindow->input2ContrastSlider,
  409.      PANEL_VALUE, currentSelection.input2.contrast, NULL);
  410.   
  411.   currentSelection.input2.saturation = editList.item[row].input2.saturation;
  412.   SaturationHandler((Panel_item)VideoFrame_mainWindow->input2SaturationSlider,
  413.             currentSelection.input2.saturation, (Event*)NULL);
  414.   xv_set(VideoFrame_mainWindow->input2SaturationSlider,
  415.      PANEL_VALUE, currentSelection.input2.saturation, NULL);
  416.   
  417.   currentSelection.input2.hue = editList.item[row].input2.hue;
  418.   HueHandler((Panel_item)VideoFrame_mainWindow->input2HueSlider,
  419.          currentSelection.input2.hue, (Event*)NULL);
  420.   xv_set(VideoFrame_mainWindow->input2HueSlider,
  421.      PANEL_VALUE, currentSelection.input2.hue, NULL);
  422.   
  423.   currentSelection.input2.width = editList.item[row].input2.width;
  424.   currentSelection.input2.height = editList.item[row].input2.height;
  425.   currentSelection.input2.x = editList.item[row].input2.x;
  426.   currentSelection.input2.y = editList.item[row].input2.y;
  427.   
  428.   tempRect.r_left = currentSelection.input2.x;
  429.   tempRect.r_top = currentSelection.input2.y;
  430.   tempRect.r_width = currentSelection.input2.width;
  431.   tempRect.r_height = currentSelection.input2.height;
  432.   frame_set_rect(VideoFrame_inputWindow2->inputWindow2, &tempRect);
  433. }                                    /* end function LoadCurrentSelection */
  434.