From: Tony Cook Date: Wed, 11 Jan 2006 03:39:25 +0000 (+0000) Subject: - added sample files missing from MANIFEST X-Git-Tag: Imager-0.48^2~44 X-Git-Url: http://git.imager.perl.org/imager.git/commitdiff_plain/7d148aa3d13d5fd0771ff59091ec81e54ac175d5?ds=sidebyside - added sample files missing from MANIFEST - added t/t92samples.t to check samples/README against MANIFEST - added inline_replace_color.pl to samples --- diff --git a/Changes b/Changes index 813a5feb..f1ce953c 100644 --- a/Changes +++ b/Changes @@ -1290,6 +1290,9 @@ Revision history for Perl extension Imager. - paste() can now paste a subset of the source image. - paste() now has better tests - paste() should now be faster for larger pastes +- added sample files missing from MANIFEST +- added t/t92samples.t to check samples/README against MANIFEST +- added inline_replace_color.pl to samples ================================================================= diff --git a/MANIFEST b/MANIFEST index 841355f1..ee7db93e 100644 --- a/MANIFEST +++ b/MANIFEST @@ -135,15 +135,20 @@ regops.perl rgb.c Reading and writing SGI rgb files rotate.c samples/README +samples/align-string.pl Demonstrate align_string method. samples/anaglyph.pl +samples/border.pl Demonstrate adding a border +samples/inline_replace_color.pl replace colors using Inline::C samples/interleave.pl -samples/replace_color.pl +samples/replace_color.pl replace colors using transform2() samples/samp-form.cgi samples/samp-image.cgi samples/samp-scale.cgi Demonstrate image upload via a HTML form samples/samp-scale.html Form for samp-scale.cgi samples/samp-tags.cgi Demonstrate image upload via a HTML form samples/samp-tags.html Form for samp-tags.cgi +samples/slant_text.pl Using $font->transform() to slant text +samples/tk-photo.pl spot.perl For making an ordered dither matrix from a spot function stackmach.c stackmach.h @@ -197,6 +202,7 @@ t/t81hlines.t Test hlines.c t/t82inline.t Test Inline::C integration t/t90cc.t t/t91pod.t Test POD with Test::Pod +t/t92samples.t t/testtools.pl tags.c testimg/bad1oflow.bmp 1-bit/pixel, overflow integer on 32-bit machines diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP index f7ed5767..e00624ef 100644 --- a/MANIFEST.SKIP +++ b/MANIFEST.SKIP @@ -28,7 +28,7 @@ Makefile$ Makefile\.old \bpm_to_blib$ \.o$ -^testimg/ +^testout ^blib/ ^Imager\.c$ ^Mandelbrot/Mandelbrot\.c$ diff --git a/samples/README b/samples/README index 5f94c7f7..3752a900 100644 --- a/samples/README +++ b/samples/README @@ -19,6 +19,11 @@ replace_color.pl http://www.perlmonks.org/?node_id=497355 +inline_replace_color.pl + + Example using Inline::C and the Imager API to replace one color with + another in an image. + interleave.pl Produce an interleaved image given the left and right images of a diff --git a/samples/inline_replace_color.pl b/samples/inline_replace_color.pl new file mode 100644 index 00000000..655a4e75 --- /dev/null +++ b/samples/inline_replace_color.pl @@ -0,0 +1,101 @@ +#!perl -w +use strict; +use Imager; + +=head1 NAME + +inline_replace_color - replace one color with another in an image, using Inline + +=head1 SYNOPSIS + + perl inline_replace_color fromcolor tocolor inimage outimage + +=head1 DESCRIPTION + +This is a simple demonstration of using Imager with Inline::C to +replace one color in an image with another. + +Most of the work is done in the inline_replace_color() function. + +=over + +=cut + +# extract parameters +my $from = shift; + +my $to = shift; + +my $in = shift; + +my $out = shift + or die "Usage: $0 fromcolor tocolor inimage outimage\n"; + +# convert the colors into objects +my $from_color = Imager::Color->new($from) + or die "Cannot convert fromcolor $from into a color: ", Imager->errstr, "\n"; + +my $to_color = Imager::Color->new($to) + or die "Cannot convert tocolor $to into a color: ", Imager->errstr, "\n"; + +# do the work +my $img = Imager->new; +$img->read(file=>$in) + or die "Cannot read image $in: ", $img->errstr, "\n"; + +# unlike the transform2() version this works in place +inline_replace_color($img, $from_color, $to_color); + +$img->write(file=>$out) + or die "Cannot write image $out: ", $img->errstr, "\n"; + +=item inline_replace_color + +Called: + + inline_replace_color($in_image, $from_color, $to_color); + +Returns a new image object with colors replaced. + +=cut + +use Inline C => <<'EOS' => WITH => 'Imager'; +void +inline_replace_color(Imager::ImgRaw img, Imager::Color from, Imager::Color to) { + int x, y, ch; + i_color c; + + for (x = 0; x < img->xsize; ++x) { + for (y = 0; y < img->ysize; ++y) { + int match = 1; + i_gpix(img, x, y, &c); + for (ch = 0; ch < img->channels; ++ch) { + if (c.channel[ch] != from->channel[ch]) { + match = 0; + break; + } + } + if (match) + i_ppix(img, x, y, to); + } + } +} +EOS + +__END__ + +=back + +=head1 REVISION + +$Revision: 816 $ + +=head1 AUTHOR + +Tony Cook + +=head1 SEE ALSO + +Imager, Imager::Inline, Imager::API, Imager::Color, Imager::Files + +=cut diff --git a/t/t92samples.t b/t/t92samples.t new file mode 100644 index 00000000..7ca1598b --- /dev/null +++ b/t/t92samples.t @@ -0,0 +1,24 @@ +#!perl -w +# packaging test - make sure we included the samples in the MANIFEST +use Test::More; +use ExtUtils::Manifest qw(maniread); + +# first build a list of samples from samples/README +open SAMPLES, "< samples/README" + or die "Cannot open samples/README: $!"; +my @sample_files; +while () { + chomp; + /^\w[\w.-]+\.\w+$/ and push @sample_files, $_; +} + +close SAMPLES; + +plan tests => scalar(@sample_files); + +my $manifest = maniread(); + +for my $filename (@sample_files) { + ok(exists($manifest->{"samples/$filename"}), + "sample file $filename in manifest"); +}