Guest User

Untitled

a guest
Jan 19th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 KB | None | 0 0
  1. /* Save for Web plug-in for The GIMP
  2. *
  3. * Copyright (C) 2006-2007, Aurimas Juška
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the
  17. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  18. * Boston, MA 02111-1307, USA.
  19. */
  20.  
  21. #include "config.h"
  22.  
  23. #include <string.h>
  24.  
  25. #include <libgimp/gimp.h>
  26. #include <libgimp/gimpui.h>
  27. #include <gdk-pixbuf/gdk-pixbuf.h>
  28.  
  29. #include "webx_main.h"
  30. #include "webx_dialog.h"
  31.  
  32. #include "plugin-intl.h"
  33.  
  34. gint global_image_ID;
  35. gint global_drawable_ID;
  36.  
  37. static void query (void);
  38. static void run (const gchar *name,
  39. gint nparams,
  40. const GimpParam *param,
  41. gint *nreturn_vals,
  42. GimpParam **return_vals);
  43. static void webx_run (gint32 image_ID,
  44. gint32 drawable_ID);
  45.  
  46. const GimpPlugInInfo PLUG_IN_INFO =
  47. {
  48. NULL, /* init_proc */
  49. NULL, /* quit_proc */
  50. query, /* query_proc */
  51. run, /* run_proc */
  52. };
  53.  
  54.  
  55. MAIN ()
  56.  
  57. static void
  58. query (void)
  59. {
  60. static GimpParamDef args[] =
  61. {
  62. { GIMP_PDB_INT32, "run-mode", "Interactive" },
  63. { GIMP_PDB_IMAGE, "image", "Input image" },
  64. { GIMP_PDB_DRAWABLE, "drawable", "Input drawable" }
  65. };
  66.  
  67. gimp_plugin_domain_register (GETTEXT_PACKAGE, LOCALEDIR);
  68.  
  69. gimp_install_procedure (PLUG_IN_PROC,
  70. N_("Optimize & save image for web"),
  71. "Optimize image for web.",
  72. "Aurimas Juška",
  73. "Aurimas Juška",
  74. "0.25",
  75. N_("Save for Web..."),
  76. "RGB*, GRAY*, INDEXED*",
  77. GIMP_PLUGIN,
  78. G_N_ELEMENTS (args), 0,
  79. args, NULL);
  80.  
  81. gimp_plugin_menu_register (PLUG_IN_PROC, "<Image>/File/Save");
  82. }
  83.  
  84. static void
  85. run (const gchar *name,
  86. gint nparams,
  87. const GimpParam *param,
  88. gint *nreturn_vals,
  89. GimpParam **return_vals)
  90. {
  91. static GimpParam values[1];
  92. gint32 image_ID;
  93. gint32 drawable_ID;
  94. GimpPDBStatusType status = GIMP_PDB_SUCCESS;
  95. GimpRunMode run_mode;
  96.  
  97. run_mode = param[0].data.d_int32;
  98. image_ID = param[1].data.d_int32;
  99. drawable_ID = param[2].data.d_int32;
  100.  
  101. values[0].type = GIMP_PDB_STATUS;
  102. values[0].data.d_status = status;
  103.  
  104. bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
  105. #ifdef HAVE_BIND_TEXTDOMAIN_CODESET
  106. bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
  107. #endif
  108. textdomain (GETTEXT_PACKAGE);
  109.  
  110. *nreturn_vals = 1;
  111. *return_vals = values;
  112.  
  113. if (run_mode == GIMP_RUN_INTERACTIVE)
  114. {
  115. webx_run (image_ID, drawable_ID);
  116. }
  117.  
  118. values[0].data.d_status = status;
  119. }
  120.  
  121. static void
  122. webx_run (gint32 image_ID, gint32 drawable_ID)
  123. {
  124. GtkWidget *dlg;
  125.  
  126. gimp_ui_init (PLUG_IN_BINARY, FALSE);
  127.  
  128. global_image_ID = image_ID;
  129. global_drawable_ID = drawable_ID;
  130.  
  131. if (gimp_image_width (image_ID) > WEBX_MAX_SIZE
  132. || gimp_image_height (image_ID) > WEBX_MAX_SIZE)
  133. {
  134. gimp_message (_("The image is too large for Save for Web!"));
  135. return;
  136. }
  137.  
  138. dlg = webx_dialog_new (image_ID, drawable_ID);
  139. webx_dialog_run (WEBX_DIALOG (dlg));
  140. }
Add Comment
Please, Sign In to add comment