Toxic Elephant

Don't bury it in your back yard!

Tips for Gimp-Perl

Posted by matijs 11/10/2004 at 12h05

After my image filtering annoyance day, I spent some more time on the problem, with more positive results.

First, I found out how to do pixel manipulations properly. It needs some incantations that are not in the man pages, but are in the source to Gimp's plugins written in C. For the basic framework of a plug-in, see Gimp-Perl's documentation and examples. For the rest, see below.

First, of course, you have to load the right modules.

use Gimp ":auto";
use Gimp::Fu;
use Gimp::Feature qw(pdl);
use PDL;

Then, the sub that actually does the work should look something like this:

sub do_something {
  my ($img, $dwb) = @_;

  my $w = $dwb->width;
  my $h = $dwb->height;
  my $gdrawable = $dwb->get;

  # make sure we can undo in one step.

  # Read values from the source region, and write them to the
  # destination region. The destination region has its dirty and shadow
  # bits set. 
  my $src_rgn = $gdrawable->pixel_rgn(0,0,$w,$h,0,0);
  my $dst_rgn = $gdrawable->pixel_rgn(0,0,$w,$h,1,1);

  # Get pixel data as a 'piddle'
  my $rect = $src_rgn->get_rect($some_x,$some_y,$some_w,$some_h);

  # Do something with $rect's data.

  # Set pixel data
  $dst_rgn->set_rect($rect, $some_x, $some_y);

  # Magic incantations found in the C destripe plug-in.

  # make sure we can undo in one step.

Be sure to read the documentation for the PDL module. It explains how to manipulate the piddle with the pixel data. It helps to print part of the piddle now and then, or its dimensions (using the dims function).

Unfortunately, the method I had come up with to destripe my images didn't exactly work right. So, I went searching again. This time, I found a page describing an easy destriping method using the Gimp.

Since the method has several steps, I decided to automate it with a plug-in. I am quite happy with the result: It works on the selected layer, even if it's invisible, it handles errors gracefully, and it only works on the selection, if one is present.

Tags no comments no trackbacks


Comments are disabled