home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2002 April / pcpro0402.iso / essentials / graphics / Gimp / gimp-src-20001226.exe / src / gimp / plug-ins / gap / gap_frontends_main.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-12-10  |  8.9 KB  |  326 lines

  1. /* gap_frontends_main.c
  2.  * 1999.11.20 hof (Wolfgang Hofer)
  3.  *
  4.  * GAP ... Gimp Animation Package
  5.  *
  6.  * This Module contains:
  7.  * - MAIN of GAP_Plugins that are frontends to external programs
  8.  *     those external programs are not available for all
  9.  *     operating systems.
  10.  *
  11.  * - query   registration of GAP Procedures (Video Menu) in the PDB
  12.  * - run     invoke the selected GAP procedure by its PDB name
  13.  * 
  14.  *
  15.  * GAP provides Animation Functions for the gimp,
  16.  * working on a series of Images stored on disk in gimps .xcf Format.
  17.  *
  18.  * Frames are Images with naming convention like this:
  19.  * Imagename_<number>.<ext>
  20.  * Example:   snoopy_0001.xcf, snoopy_0002.xcf, snoopy_0003.xcf
  21.  *
  22.  * if gzip is installed on your system you may optional
  23.  * use gziped xcf frames with extensions ".xcfgz"
  24.  *
  25.  */
  26. /* The GIMP -- an image manipulation program
  27.  * Copyright (C) 1995 Spencer Kimball and Peter Mattis
  28.  *
  29.  * This program is free software; you can redistribute it and/or modify
  30.  * it under the terms of the GNU General Public License as published by
  31.  * the Free Software Foundation; either version 2 of the License, or
  32.  * (at your option) any later version.
  33.  *
  34.  * This program is distributed in the hope that it will be useful,
  35.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  36.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  37.  * GNU General Public License for more details.
  38.  *
  39.  * You should have received a copy of the GNU General Public License
  40.  * along with this program; if not, write to the Free Software
  41.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  42.  */
  43.  
  44. static char *gap_main_version =  "1.1.29b; 2000/11/25";
  45.  
  46. /* revision history:
  47.  * gimp    1.1.29b; 2000/11/25  hof: use gap lock procedures, update e-mail adress + main version
  48.  * gimp    1.1.11b; 1999/11/20  hof: added gap_decode_xanim, fixed typo in mpeg encoder menu path
  49.  *                                   based on parts that were found in gap_main.c before.
  50.  */
  51.  
  52. /* SYTEM (UNIX) includes */ 
  53. #include <stdio.h>
  54. #include <string.h>
  55. #include <stdlib.h>
  56.  
  57. /* GIMP includes */
  58. #include "gtk/gtk.h"
  59. #include "config.h"
  60. #include "libgimp/stdplugins-intl.h"
  61. #include "libgimp/gimp.h"
  62.  
  63. /* GAP includes */
  64. #include "gap_lib.h"
  65. #include "gap_mpege.h"
  66. #include "gap_decode_xanim.h"
  67. #include "gap_arr_dialog.h"
  68.  
  69. /* ------------------------
  70.  * global gap DEBUG switch
  71.  * ------------------------
  72.  */
  73.  
  74. /* int gap_debug = 1; */    /* print debug infos */
  75. /* int gap_debug = 0; */    /* 0: dont print debug infos */
  76.  
  77. int gap_debug = 0;
  78.  
  79. static void query(void);
  80. static void run(char *name, int nparam, GimpParam *param,
  81.                 int *nretvals, GimpParam **retvals);
  82.  
  83. GimpPlugInInfo PLUG_IN_INFO =
  84. {
  85.   NULL,  /* init_proc */
  86.   NULL,  /* quit_proc */
  87.   query, /* query_proc */
  88.   run,   /* run_proc */
  89. };
  90.  
  91. MAIN ()
  92.  
  93. static void
  94. query ()
  95. {
  96.   static GimpParamDef args_xanim[] =
  97.   {
  98.     {GIMP_PDB_INT32, "run_mode", "Interactive"},
  99.     {GIMP_PDB_IMAGE, "image", "(unused)"},
  100.     {GIMP_PDB_DRAWABLE, "drawable", "(unused)"},
  101.   };
  102.   static int nargs_xanim = sizeof(args_xanim) / sizeof(args_xanim[0]);
  103.  
  104.   static GimpParamDef args_xanim_ext[] =
  105.   {
  106.     {GIMP_PDB_INT32, "run_mode", "Interactive"},
  107.   };
  108.   static int nargs_xanim_ext = sizeof(args_xanim_ext) / sizeof(args_xanim_ext[0]);
  109.  
  110.   static GimpParamDef args_mpege[] =
  111.   {
  112.     {GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive"},
  113.     {GIMP_PDB_IMAGE, "image", "Input image (one of the Anim Frames)"},
  114.     {GIMP_PDB_DRAWABLE, "drawable", "Input drawable (unused)"},
  115.   };
  116.   static int nargs_mpege = sizeof(args_mpege) / sizeof(args_mpege[0]);
  117.  
  118.   static GimpParamDef *return_vals = NULL;
  119.   static int nreturn_vals = 0;
  120.  
  121.  
  122.   gimp_install_procedure("plug_in_gap_xanim_decode",
  123.              "This plugin calls xanim to split any video to anim frames. (xanim exporting edition must be installed on your system)",
  124.              "",
  125.              "Wolfgang Hofer (hof@gimp.org)",
  126.              "Wolfgang Hofer",
  127.              gap_main_version,
  128.              N_("<Image>/Video/Split Video to Frames/Any XANIM readable..."),
  129.              NULL,
  130.              GIMP_PLUGIN,
  131.              nargs_xanim, nreturn_vals,
  132.              args_xanim, return_vals);
  133.  
  134.   gimp_install_procedure("extension_gap_xanim_decode",
  135.              "This plugin calls xanim to split any video to anim frames. (xanim exporting edition must be installed on your system)",
  136.              "",
  137.              "Wolfgang Hofer (hof@gimp.org)",
  138.              "Wolfgang Hofer",
  139.              gap_main_version,
  140.              N_("<Toolbox>/Xtns/Split Video to Frames/Any XANIM readable..."),
  141.              NULL,
  142.              GIMP_EXTENSION,
  143.              nargs_xanim_ext, nreturn_vals,
  144.              args_xanim_ext, return_vals);
  145.  
  146.   gimp_install_procedure("plug_in_gap_mpeg_encode",
  147.              "This plugin calls mpeg_encode to convert anim frames to MPEG1, or just generates a param file for mpeg_encode. (mpeg_encode must be installed on your system)",
  148.              "",
  149.              "Wolfgang Hofer (hof@gimp.org)",
  150.              "Wolfgang Hofer",
  151.              gap_main_version,
  152.              N_("<Image>/Video/Encode/MPEG1..."),
  153.              "*",
  154.              GIMP_PLUGIN,
  155.              nargs_mpege, nreturn_vals,
  156.              args_mpege, return_vals);
  157.  
  158.  
  159.   gimp_install_procedure("plug_in_gap_mpeg2encode",
  160.              "This plugin calls mpeg2encode to convert anim frames to MPEG1 or MPEG2, or just generates a param file for mpeg2encode. (mpeg2encode must be installed on your system)",
  161.              "",
  162.              "Wolfgang Hofer (hof@gimp.org)",
  163.              "Wolfgang Hofer",
  164.              gap_main_version,
  165.              N_("<Image>/Video/Encode/MPEG2..."),
  166.              "*",
  167.              GIMP_PLUGIN,
  168.              nargs_mpege, nreturn_vals,
  169.              args_mpege, return_vals);
  170.  
  171.  
  172. }    /* end query */
  173.  
  174.  
  175.  
  176. static void
  177. run (char    *name,
  178.      int      n_params,
  179.      GimpParam  *param,
  180.      int     *nreturn_vals,
  181.      GimpParam **return_vals)
  182. {
  183.   char       *l_env;
  184.   
  185.   char        l_extension[32];
  186.   static GimpParam values[2];
  187.   GimpRunModeType run_mode;
  188.   GimpPDBStatusType status = GIMP_PDB_SUCCESS;
  189.   gint32     image_id;
  190.   gint32     lock_image_id;
  191.   gint32     nr;
  192.    
  193.   gint32     l_rc;
  194.  
  195.   *nreturn_vals = 1;
  196.   *return_vals = values;
  197.   nr = 0;
  198.   l_rc = 0;
  199.  
  200.  
  201.   l_env = g_getenv("GAP_DEBUG");
  202.   if(l_env != NULL)
  203.   {
  204.     if((*l_env != 'n') && (*l_env != 'N')) gap_debug = 1;
  205.   }
  206.  
  207.   run_mode = param[0].data.d_int32;
  208.   image_id = -1;
  209.   lock_image_id = image_id;
  210.  
  211.   if(gap_debug) fprintf(stderr, "\n\ngap_main: debug name = %s\n", name);
  212.  
  213.   if (strcmp (name, "extension_gap_xanim_decode") != 0)
  214.   {
  215.     image_id = param[1].data.d_image;
  216.     lock_image_id = image_id;
  217.  
  218.     /* check for locks */
  219.     if(p_gap_lock_is_locked(lock_image_id, run_mode))
  220.     {
  221.          status = GIMP_PDB_EXECUTION_ERROR;
  222.          values[0].type = GIMP_PDB_STATUS;
  223.          values[0].data.d_status = status;
  224.          return ;
  225.     }
  226.  
  227.  
  228.     /* set LOCK on current image (for all gap_plugins) */
  229.     p_gap_lock_set(lock_image_id);
  230.   }
  231.   
  232.   if (run_mode == GIMP_RUN_NONINTERACTIVE) {
  233.     INIT_I18N();
  234.   } else {
  235.     INIT_I18N_UI();
  236.   }
  237.  
  238.   if ((strcmp (name, "plug_in_gap_xanim_decode") == 0)
  239.   ||  (strcmp (name, "extension_gap_xanim_decode") == 0))
  240.   {
  241.       if (run_mode == GIMP_RUN_NONINTERACTIVE)
  242.       {
  243.           status = GIMP_PDB_CALLING_ERROR;
  244.           /* planed: define non interactive PARAMS */
  245.       }
  246.  
  247.       if (status == GIMP_PDB_SUCCESS)
  248.       {
  249.         /* planed: define non interactive PARAMS */
  250.  
  251.         l_rc = gap_xanim_decode(run_mode /* more PARAMS */);
  252.  
  253.       }
  254.   }
  255.   else if (strcmp (name, "plug_in_gap_mpeg_encode") == 0)
  256.   {
  257.       if (run_mode == GIMP_RUN_NONINTERACTIVE)
  258.       {
  259.         if (n_params != 3)
  260.         {
  261.           status = GIMP_PDB_CALLING_ERROR;
  262.         }
  263.         else
  264.         {
  265.           /* planed: define non interactive PARAMS */
  266.           l_extension[sizeof(l_extension) -1] = '\0';
  267.         }
  268.       }
  269.  
  270.       if (status == GIMP_PDB_SUCCESS)
  271.       {
  272.  
  273.         image_id    = param[1].data.d_image;
  274.         /* planed: define non interactive PARAMS */
  275.  
  276.         l_rc = gap_mpeg_encode(run_mode, image_id, MPEG_ENCODE /* more PARAMS */);
  277.  
  278.       }
  279.   }
  280.   else if (strcmp (name, "plug_in_gap_mpeg2encode") == 0)
  281.   {
  282.       if (run_mode == GIMP_RUN_NONINTERACTIVE)
  283.       {
  284.         if (n_params != 3)
  285.         {
  286.           status = GIMP_PDB_CALLING_ERROR;
  287.         }
  288.         else
  289.         {
  290.           /* planed: define non interactive PARAMS */
  291.           l_extension[sizeof(l_extension) -1] = '\0';
  292.         }
  293.       }
  294.  
  295.       if (status == GIMP_PDB_SUCCESS)
  296.       {
  297.  
  298.         image_id    = param[1].data.d_image;
  299.         /* planed: define non interactive PARAMS */
  300.  
  301.         l_rc = gap_mpeg_encode(run_mode, image_id, MPEG2ENCODE /* more PARAMS */);
  302.  
  303.       }
  304.   }
  305.  
  306.   /* ---------- return handling --------- */
  307.  
  308.  if(l_rc < 0)
  309.  {
  310.     status = GIMP_PDB_EXECUTION_ERROR;
  311.  }
  312.  
  313.   
  314.  if (run_mode != GIMP_RUN_NONINTERACTIVE)
  315.     gimp_displays_flush();
  316.  
  317.   values[0].type = GIMP_PDB_STATUS;
  318.   values[0].data.d_status = status;
  319.  
  320.   if (strcmp (name, "extension_gap_xanim_decode") != 0)
  321.   {
  322.     /* remove LOCK on this image for all gap_plugins */
  323.      p_gap_lock_remove(lock_image_id);
  324.   }
  325. }
  326.