home *** CD-ROM | disk | FTP | other *** search
/ ftp.sunet.sepub/pictures / 2014.11.ftp.sunet.se-pictures.tar / ftp.sunet.se / pub / pictures / ACiD-artpacks / programs / unix / editors / gimp-plugins-unstable-0_99_23_tar.gz / gimp-plugins-unstable-0_99_23_tar / gimp-plugins-unstable-0.99.23 / icon / icon.c next >
C/C++ Source or Header  |  1998-02-24  |  5KB  |  156 lines

  1. /* icon.c                                      */
  2. /* This is a File input and output filter for     */
  3. /* Gimp. It loads and saves images in windows(TM) */
  4. /* icon bitmap format.                            */
  5. /* Some parts are taken from the BMP plugin by    */
  6. /* Alexander Schulz                  */
  7. /*                          */
  8. /* Lance Dillon                      */
  9. /* riffraff@gte.net                  */
  10.  
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14. #include <libgimp/gimp.h>
  15. #include <gtk/gtk.h>
  16. #include "icon.h"
  17.  
  18.  
  19. char *prog_name="icon";
  20. char *filename;
  21. int interactive_icon;
  22.  
  23. /* Declare some local functions.
  24.  */
  25. static void   query      (void);
  26. static void   run        (char    *name,
  27.                           int      nparams,
  28.                           GParam  *param,
  29.                           int     *nreturn_vals,
  30.                           GParam **return_vals);
  31. /*static gint32 load_image(char *filename);
  32. static gint save_image(char *filename, gint32 image_ID, 
  33.                gint32 drawable_ID); */
  34.  
  35.  
  36. GPlugInInfo PLUG_IN_INFO =
  37. {
  38.   NULL,    /* init_proc */
  39.   NULL,    /* quit_proc */
  40.   query,   /* query_proc */
  41.   run,     /* run_proc */
  42. };
  43.  
  44. MAIN ()
  45.  
  46. static void
  47. query (void) {
  48.   static GParamDef load_args[] = {
  49.     { PARAM_INT32, "run_mode", "Interactive, non-interactive" },
  50.     { PARAM_STRING, "filename", "The name of the file to load" },
  51.     { PARAM_STRING, "raw_filename", "The name entered" },
  52.   };
  53.   static GParamDef load_return_vals[] = {
  54.     { PARAM_IMAGE, "image", "Output image" },
  55.   };
  56.   static int nload_args = sizeof (load_args) / sizeof (load_args[0]);
  57.   static int nload_return_vals = sizeof (load_return_vals) / sizeof (load_return_vals[0]);
  58.  
  59.   static GParamDef save_args[] = {
  60.     { PARAM_INT32, "run_mode", "Interactive, non-interactive" },
  61.     { PARAM_IMAGE, "image", "Input image" },
  62.     { PARAM_DRAWABLE, "drawable", "Drawable to save" },
  63.     { PARAM_STRING, "filename", "The name of the file to save the image in" },
  64.     { PARAM_STRING, "raw_filename", "The name entered" },
  65.   };
  66.   static int nsave_args = sizeof (save_args) / sizeof (save_args[0]);
  67.   
  68.   gimp_install_procedure ("file_icon_load",
  69.                           "Loads files of Windows ICO file format",
  70.                           "Loads files of Windows ICO file format",
  71.                           "Lance Dillon",
  72.                           "Lance DIllon",
  73.                           "1997",
  74.                           "<Load>/ICO",
  75.                           NULL,
  76.                           PROC_PLUG_IN,
  77.                           nload_args, nload_return_vals,
  78.                           load_args, load_return_vals);
  79.  
  80.   gimp_install_procedure ("file_icon_save",
  81.                           "Saves files in Windows ICO file format",
  82.                           "Saves files in Windows ICO file format",
  83.                           "Lance Dillon",
  84.                           "Lance Dillon",
  85.                           "1997",
  86.                           "<Save>/ICO",
  87.                           "INDEXED*",
  88.                           PROC_PLUG_IN,
  89.                           nsave_args, 0,
  90.                           save_args, NULL);
  91.  
  92. /*  gimp_register_magic_load_handler ("file_icon_load", "ico", "", "0,string,BM"); */
  93. /*  gimp_register_magic_load_handler ("file_icon_load", "ico", "", ""); */
  94.   gimp_register_load_handler ("file_icon_load", "ico", "");
  95.   gimp_register_save_handler ("file_icon_save", "ico", "");
  96. }
  97.  
  98. static void
  99. run (char    *name,
  100.      int      nparams,
  101.      GParam  *param,
  102.      int     *nreturn_vals,
  103.      GParam **return_vals) {
  104.   static GParam values[2];
  105.   GStatusType status = STATUS_SUCCESS;
  106.   GRunModeType run_mode;
  107.   gint32 image_ID;
  108.   
  109.   run_mode = param[0].data.d_int32;
  110.  
  111.   *nreturn_vals = 1;
  112.   *return_vals = values;
  113.   values[0].type = PARAM_STATUS;
  114.   values[0].data.d_status = STATUS_CALLING_ERROR;
  115.  
  116.   if (!strcmp(name, "file_icon_load")) {
  117.     image_ID = ReadICON(param[1].data.d_string);
  118.  
  119.     if (image_ID != -1) {
  120.       *nreturn_vals = 2;
  121.       values[0].data.d_status = STATUS_SUCCESS;
  122.       values[1].type = PARAM_IMAGE;
  123.       values[1].data.d_image = image_ID;
  124.     } else {
  125.       values[0].data.d_status = STATUS_EXECUTION_ERROR;
  126.     }
  127.   } else if (!strcmp(name, "file_icon_save")) {
  128.     switch (run_mode) {
  129.       case RUN_INTERACTIVE:
  130.     interactive_icon = TRUE;
  131.     break;
  132.  
  133.       case RUN_NONINTERACTIVE:
  134.     /*  Make sure all the arguments are there!  */
  135.     interactive_icon = FALSE;
  136.     if (nparams != 5)
  137.       status = STATUS_CALLING_ERROR;
  138.     break;
  139.  
  140.       case RUN_WITH_LAST_VALS:
  141.     interactive_icon = FALSE;
  142.     break;
  143.  
  144.       default:
  145.     break;
  146.     }
  147.  
  148.     *nreturn_vals = 1;
  149.     if (WriteICON(param[3].data.d_string, param[1].data.d_int32, param[2].data.d_int32)) {
  150.       values[0].data.d_status = STATUS_SUCCESS;
  151.     } else
  152.       values[0].data.d_status = STATUS_EXECUTION_ERROR;
  153.   }
  154. }
  155.  
  156.