Seth Burgess <sjburges@xxxxxxxxx> writes: | | I agree about your goal of exporting all functionality | through the PDB. | | However, the *_cmds.c files are auto-generated by the | tool pdbgen. Changing the files in the pdb directory | would be the proper fix; your patch requires someone | to reverse engineer what you've changed and add it to | the pdb file. This will happen eventually, but its | much faster to send a patch to the correct file in the | first place. Okay, attached is a patch that is reverse-engineered from the previous one. I missed the comment of "autogenerated by pdbgen.pl" at the top of color_cmds.c. quinet@xxxxxxxxxx (Raphael Quinet) writes: | | > For this and some other hints, please read HACKING. | | Unfortunately, the HACKING file is not part of the Gimp distribution. | It is only available if you are using CVS, and many people are sending | patches from the source tarballs, so they do not have access to these | instructions. It could be a good idea to include the HACKING file in | the standard distribution, so the people who do not use CVS can still | send useful patches (there are various reasons why people do not use | CVS: they do not know about it, they do not want to use it because the | current version is unstable, or they simply cannot use CVS at all | because a company firewall prevents them from accessing the server). Thanks. When I received your message I was looking for the file around the source tree :-) BTW, I'm not sure that the procedure name gimp-levels-auto is a good name. Please feel free to change it. gimp-auto-levels is another candidate, I believe. Regards, -- KAJIYAMA, Tamito <kajiyama@xxxxxxxxxxxxxxxxxxxxxxxx> diff -ru gimp-1.2.1.orig/tools/pdbgen/pdb/color.pdb gimp-1.2.1/tools/pdbgen/pdb/color.pdb --- gimp-1.2.1.orig/tools/pdbgen/pdb/color.pdb Mon Dec 25 01:40:47 2000 +++ gimp-1.2.1/tools/pdbgen/pdb/color.pdb Wed Mar 21 03:58:42 2001 @@ -175,6 +175,125 @@ } } +sub levels_auto { + $blurb = 'Modifies intensity levels in the specified drawable.'; + + $help = <<'HELP'; +This tool automatically adjusts intensity levels in the specified +drawable. This tool is only valid on RGB color and grayscale +images. It will not operate on indexed drawables. +HELP + + &std_pdb_misc; + + @inargs = ( + &drawable_arg, + &channel_arg + ); + + %invoke = ( + vars => [ 'PixelRegion srcPR, destPR', 'int x1, y1, x2, y2', + 'GimpLut *lut', 'int i', + 'int low_input[5]', + 'int high_input[5]', + 'int low_output[5]', + 'int high_output[5]', + 'double gamma[5]', + 'GimpHistogram *hist', + 'double count, new_count, percentage, next_percentage'], + code => <<'CODE' +{ + if (gimp_drawable_is_indexed (drawable) || + (!gimp_drawable_has_alpha (drawable) && channel == ALPHA_LUT) || + (gimp_drawable_is_gray (drawable) && channel != GRAY_LUT + && channel != ALPHA_LUT)) + success = FALSE; + else + { + for (i = 0; i < 5; i++) + { + low_input[i] = 0; + high_input[i] = 255; + low_output[i] = 0; + high_output[i] = 255; + gamma[i] = 1.0; + } + + hist = gimp_histogram_new (); + gimp_histogram_calculate_drawable (hist, drawable); + + count = gimp_histogram_get_count (hist, 0, 255); + + if (count == 0.0) + { + low_input[channel] = 0; + high_input[channel] = 0; + } + else + { + /* Set the low input */ + new_count = 0.0; + for (i = 0; i < 255; i++) + { + new_count += gimp_histogram_get_value(hist, channel, i); + percentage = new_count / count; + next_percentage = + (new_count + gimp_histogram_get_value (hist, + channel, + i + 1)) / count; + if (fabs (percentage - 0.006) < + fabs (next_percentage - 0.006)) + { + low_input[channel] = i + 1; + break; + } + } + /* Set the high input */ + new_count = 0.0; + for (i = 255; i > 0; i--) + { + new_count += gimp_histogram_get_value(hist, channel, i); + percentage = new_count / count; + next_percentage = + (new_count + gimp_histogram_get_value (hist, + channel, + i - 1)) / count; + if (fabs (percentage - 0.006) < + fabs (next_percentage - 0.006)) + { + high_input[channel] = i - 1; + break; + } + } + } + + gimp_histogram_free (hist); + + /* setup the lut */ + lut = levels_lut_new (gamma, low_input, high_input, + low_output, high_output, + gimp_drawable_bytes (drawable)); + + /* The application should occur only within selection bounds */ + gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2); + + pixel_region_init (&srcPR, gimp_drawable_data (drawable), + x1, y1, (x2 - x1), (y2 - y1), FALSE); + pixel_region_init (&destPR, gimp_drawable_shadow (drawable), + x1, y1, (x2 - x1), (y2 - y1), TRUE); + + pixel_regions_process_parallel ((p_func) gimp_lut_process, lut, 2, + &srcPR, &destPR); + + gimp_lut_free(lut); + gimp_drawable_merge_shadow (drawable, TRUE); + drawable_update (drawable, x1, y1, (x2 - x1), (y2 - y1)); + } +} +CODE + ); +} + sub posterize { $blurb = 'Posterize the specified drawable.'; @@ -761,9 +880,9 @@ ); } -@headers = qw("gimpimage.h" "gimpdrawable.h" "gimplut.h" "lut_funcs.h"); +@headers = qw("gimpimage.h" "gimpdrawable.h" "gimplut.h" "lut_funcs.h" "libgimp/gimpmath.h"); -@procs = qw(brightness_contrast levels posterize desaturate equalize invert +@procs = qw(brightness_contrast levels levels_auto posterize desaturate equalize invert curves_spline curves_explicit color_balance histogram hue_saturation threshold); %exports = (app => [@procs], lib => [@procs]);