#!/usr/bin/perl -w # # Example 5-3: Colorize. A plug-in for the Gimp, written in Perl. use strict; use Gimp qw(:auto N_); use Gimp::Fu; use PDL; use Gimp::Util; register( "perl_fu_colorize_with_progress", # Name "Colorify the dark parts of an image.", # Blurb "=pod(HELP)", # Help "=pod(AUTHOR)", # Author "=pod(COPYRIGHT)", # Copyright "=pod(DATE)", # Date N_ "/ORA Examples/Colorize", # Menu path "RGB*, GRAY*", # Images accepted # The parameters [ [ PF_COLOR, "color", "The color to use", [255, 0, 0]], ], # return values [], \&colorize ); sub colorize { # First get the parameters passed to the procedure... my ($img, $drawable, $color) = @_; Gimp->progress_init("Colorizing..."); unless ($drawable->is_rgb()) { $img->convert_rgb(); } unless ($drawable->mask_bounds) { $img->selection_all; } my @bounds = $drawable->bounds; # Provided by Gimp::Util my $gdrawable = $drawable->get; my $src_region = $gdrawable->pixel_rgn(@bounds, 0, 0); my $dest_region = $gdrawable->pixel_rgn(@bounds, 1, 1); # pixel_rgns_register returns a PixelRegionIterator my $iterator = Gimp->pixel_rgns_register($src_region, $dest_region); my ($pixel_data, $channel); my $area = $bounds[2]*$bounds[3]; my $progress = 0; do { $pixel_data = $src_region->data; foreach (0..2) { # Get the pixel data for a single channel $channel = index($pixel_data, $_); $channel .= 255-(255-$channel)*(255-$color->[$_])/255; } $dest_region->data($pixel_data); $progress += ($src_region->w * $src_region->h)/$area; Gimp->progress_update($progress); } while (Gimp->pixel_rgns_process($iterator)); $drawable->merge_shadow(1); $drawable->update(@bounds); return (); } exit main; # Embedded POD documentation follows =head1 NAME Colorize with progress bar =head1 HELP Colorize a region. Update the progress bar to let the user know how things are going. =head1 AUTHOR Shawn Wallace =head1 COPYRIGHT (c) 2003 The Institute for Folk Computing =head1 DATE 2003-03-12