/* This is an attempt at a GIMP plug-in sample * for CS430, Spring 2000, Ray S. Babcock. * It is to bump an area of the image by a small number * of gray levels. * */ /**************************************************************************** * This is a plugin for the GIMP v 1.0 or later. ****************************************************************************/ #include #include "libgimp/gimp.h" #include #include #include "gtk/gtk.h" /* The prototype for the query function. Called by gimp to find out what the plug-in does. */ static void query(void); /* The prototype for the run function. Calleb ty gimp when you want to execute the code contained within the plug-in. */ static void run( char *name, int nparams, GimpParam *param, int *nreturn_vals, GimpParam **return_vals ); /* The names for the functions are sent to gimp in the following structure.*/ GimpPlugInInfo PLUG_IN_INFO = { NULL, /* init_proc called when the gimp application initially starts up. There is NO init process in this case. */ NULL, /* quit_proc called when the gimp application initially exits. There is NO quit process in this case. */ query, /* query_proc called by gimp so that the plug-in can inform gimp of what it does (i.e. installing a procedure database procedure. There is a procedure called query in this case. */ run, /* run_proc called when the plug-in is run. This is the function that does the work you want to be done. There is a procedure called run in this case. */ }; /* Other local function prototypes are defined here. */ static void bumpit(GimpDrawable *drawable); /* The main function for the plug-in. There is no real main. This is a link to the gimp calling system. It is actually a macro defined in libgimp/gimp.h */ MAIN(); /********************************* * * query() - query_proc * * called by the GIMP to learn about this plug-in * ********************************/ void query (void) { static GimpParamDef args[] = { { GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive" }, { GIMP_PDB_IMAGE, "image", "Input image (unused)" }, { GIMP_PDB_DRAWABLE, "drawable", "Input drawable" }, { GIMP_PDB_INT32, "dummy", "dummy" } }; /* some space for return parameters */ static gint nargs = sizeof (args) / sizeof (args[0]); /* The install procedure telling gimp what's what */ gimp_install_procedure ("Babcock's bump", /* plug-in name */ "A simple bump modification example.", /* short description */ "A help string goes here", /* help string */ "Ray S. Babcock", /* Author */ "Ray S. Babcock", /* copyright names */ "1997", /* copyright date */ "/Filters/Misc./Babcock", /* menu path name */ "RGB*, GRAY*", /* file types accepted */ GIMP_PLUGIN, /* type of plug-in */ nargs, 0, /* first set returns */ args, NULL); /* second set returns */ } /********************************* * * run() - main routine * * This handles the main interaction with the GIMP itself, * and invokes the routine that actually does the work. * ********************************/ void run (char *name, int nparams, GimpParam *param, int *nreturn_vals, GimpParam **return_vals) { GimpParam values[1]; GimpRunModeType run_mode; GimpDrawable * drawable; GimpPDBStatusType status = GIMP_PDB_SUCCESS; *nreturn_vals = 1; *return_vals = values; values[0].type = GIMP_PDB_STATUS; values[0].data.d_status = status; drawable = gimp_drawable_get(param[2].data.d_drawable); run_mode = param[0].data.d_int32; /* works not on INDEXED images */ if (gimp_drawable_is_indexed (drawable->id) || gimp_drawable_is_gray (drawable->id) || gimp_drawable_is_rgb (drawable->id)) { /* Determine whether we are interactive or not */ switch (run_mode) { /* If we're running interactively, do the work */ case GIMP_RUN_INTERACTIVE: bumpit(drawable); break; /* If we're not interactive (probably scripting) we just stop for now.*/ case GIMP_RUN_NONINTERACTIVE: printf("Can't run non-interactive for now!\n"); exit(-1); } /* end of switch */ } else { status = GIMP_PDB_EXECUTION_ERROR; /* I don't know what this looks like to user, rb */ } values[0].data.d_status = status; if (status == GIMP_PDB_SUCCESS) gimp_drawable_detach(drawable); } static void bumpit(GimpDrawable *drawable) { /* Local variables to do the scan */ GimpPixelRgn srcPR; gint width, height; gint bytes; gint bump_value=40; gint i,j; guchar buf; width = drawable->width; height = drawable->height; bytes = drawable->bpp; printf("width,height,bpp = %d,%d,%d\n", width, height, bytes); /* initialize the region data structures */ gimp_pixel_rgn_init(&srcPR, drawable, 0, 0, 512, 512, TRUE, FALSE); /* loop through a small area to save time */ for (i=64; i<192; i++) { for (j=64; j<192; j++) { gimp_pixel_rgn_get_pixel(&srcPR, &buf, i, j); buf += bump_value; gimp_pixel_rgn_set_pixel(&srcPR, &buf, i, j); }; }; printf("all done\n"); gimp_drawable_flush(drawable); gimp_drawable_merge_shadow (drawable->id, TRUE); /* First two numbers are x,y of start * second two numbers are width,height of rectangle */ gimp_drawable_update(drawable->id, 64, 64, 128, 128); gimp_displays_flush(); }