]> git.imager.perl.org - imager.git/commitdiff
- added sample files missing from MANIFEST
authorTony Cook <tony@develop=help.com>
Wed, 11 Jan 2006 03:39:25 +0000 (03:39 +0000)
committerTony Cook <tony@develop=help.com>
Wed, 11 Jan 2006 03:39:25 +0000 (03:39 +0000)
- added t/t92samples.t to check samples/README against MANIFEST
- added inline_replace_color.pl to samples

Changes
MANIFEST
MANIFEST.SKIP
samples/README
samples/inline_replace_color.pl [new file with mode: 0644]
t/t92samples.t [new file with mode: 0644]

diff --git a/Changes b/Changes
index 813a5feb4e4202876132a3319f4551ee2971373b..f1ce953c4a5c205c22d5ee581d1b145461c47e73 100644 (file)
--- 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
 - 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
 
 =================================================================
 
 
 =================================================================
 
index 841355f145ee64c1e0c027336bbc5c50ed44d844..ee7db93e9def06c2d4a66370898ee49befb75963 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -135,15 +135,20 @@ regops.perl
 rgb.c           Reading and writing SGI rgb files
 rotate.c
 samples/README
 rgb.c           Reading and writing SGI rgb files
 rotate.c
 samples/README
+samples/align-string.pl Demonstrate align_string method.
 samples/anaglyph.pl
 samples/anaglyph.pl
+samples/border.pl       Demonstrate adding a border
+samples/inline_replace_color.pl  replace colors using Inline::C
 samples/interleave.pl
 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/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
 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/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
 t/testtools.pl
 tags.c
 testimg/bad1oflow.bmp   1-bit/pixel, overflow integer on 32-bit machines
index f7ed5767275c89cfc991470e8da82c911ebab368..e00624ef135680a87cff75213bcf416fce4820d4 100644 (file)
@@ -28,7 +28,7 @@ Makefile$
 Makefile\.old
 \bpm_to_blib$
 \.o$
 Makefile\.old
 \bpm_to_blib$
 \.o$
-^testimg/
+^testout
 ^blib/
 ^Imager\.c$
 ^Mandelbrot/Mandelbrot\.c$
 ^blib/
 ^Imager\.c$
 ^Mandelbrot/Mandelbrot\.c$
index 5f94c7f771c7265526efa4afd3655b14ccd2dd31..3752a900321460e80bf0329d2fddef1c46796b71 100644 (file)
@@ -19,6 +19,11 @@ replace_color.pl
 
   http://www.perlmonks.org/?node_id=497355
 
 
   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
 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 (file)
index 0000000..655a4e7
--- /dev/null
@@ -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 <tony@develop-help.com>
+
+=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 (file)
index 0000000..7ca1598
--- /dev/null
@@ -0,0 +1,24 @@
+#!perl -w
+# packaging test - make sure we included the samples in the MANIFEST <sigh>
+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 (<SAMPLES>) {
+  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");
+}