Created
July 2, 2016 01:40
-
-
Save mikespook/06a514d6f0a9e02f501563e07e736434 to your computer and use it in GitHub Desktop.
GIMP Plug-in in Golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Comes from http://developer.gimp.org/writing-a-plug-in/1/hello.c | |
#include <libgimp/gimp.h> | |
static void query (void); | |
static void run (const gchar *name, | |
gint nparams, | |
const GimpParam *param, | |
gint *nreturn_vals, | |
GimpParam **return_vals); | |
GimpPlugInInfo PLUG_IN_INFO = | |
{ | |
NULL, | |
NULL, | |
query, | |
run | |
}; | |
// Remove the main() entry | |
// MAIN() | |
static void | |
query (void) | |
{ | |
static GimpParamDef args[] = | |
{ | |
{ | |
GIMP_PDB_INT32, | |
"run-mode", | |
"Run mode" | |
}, | |
{ | |
GIMP_PDB_IMAGE, | |
"image", | |
"Input image" | |
}, | |
{ | |
GIMP_PDB_DRAWABLE, | |
"drawable", | |
"Input drawable" | |
} | |
}; | |
gimp_install_procedure ( | |
"plug-in-hello", | |
"Hello, world!", | |
"Displays \"Hello, world!\" in a dialog", | |
"David Neary", | |
"Copyright David Neary", | |
"2004", | |
"_Hello world...", | |
"RGB*, GRAY*", | |
GIMP_PLUGIN, | |
G_N_ELEMENTS (args), 0, | |
args, NULL); | |
gimp_plugin_menu_register ("plug-in-hello", | |
"<Image>/Filters/Misc"); | |
} | |
static void | |
run (const gchar *name, | |
gint nparams, | |
const GimpParam *param, | |
gint *nreturn_vals, | |
GimpParam **return_vals) | |
{ | |
static GimpParam values[1]; | |
GimpPDBStatusType status = GIMP_PDB_SUCCESS; | |
GimpRunMode run_mode; | |
/* Setting mandatory output values */ | |
*nreturn_vals = 1; | |
*return_vals = values; | |
values[0].type = GIMP_PDB_STATUS; | |
values[0].data.d_status = status; | |
/* Getting run_mode - we won't display a dialog if | |
* we are in NONINTERACTIVE mode */ | |
run_mode = param[0].data.d_int32; | |
if (run_mode != GIMP_RUN_NONINTERACTIVE) | |
g_message("Hello, world!\n"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
// #cgo pkg-config: gtk+-2.0 gimp-2.0 | |
// #include <hello.c> | |
import "C" | |
import ( | |
"os" | |
"unsafe" | |
) | |
// Write you own main entry | |
func gimp_main(args []string) { | |
outer := make([]*C.char, len(args)+1) | |
for i, inner := range args { | |
outer[i] = C.CString(inner) | |
} | |
C.gimp_main(&C.PLUG_IN_INFO, C.gint(len(args)), (**C.gchar)(unsafe.Pointer(&outer[0]))) | |
} | |
func main() { | |
gimp_main(os.Args) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment