]> git.imager.perl.org - imager.git/commitdiff
- convert dynfilt/flines.c to Imager::Filter::Flines
authorTony Cook <tony@develop=help.com>
Thu, 12 Jan 2006 01:29:26 +0000 (01:29 +0000)
committerTony Cook <tony@develop=help.com>
Thu, 12 Jan 2006 01:29:26 +0000 (01:29 +0000)
Changes
Flines/Flines.pm [new file with mode: 0644]
Flines/Flines.xs [new file with mode: 0644]
Flines/Makefile.PL [new file with mode: 0644]
Flines/t/t00flines.t [new file with mode: 0644]
MANIFEST
MANIFEST.SKIP

diff --git a/Changes b/Changes
index e95eb324d51acd7acfaafc010fe3191771ad04f8..c45afda6d5c9a918e411a8d4595bb283f235f52a 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1295,6 +1295,7 @@ Revision history for Perl extension Imager.
 - added inline_replace_color.pl to samples
 - constify the Imager API
 - document Imager::Filter::Mandelbrot
+- convert dynfilt/flines.c to Imager::Filter::Flines
 
 =================================================================
 
diff --git a/Flines/Flines.pm b/Flines/Flines.pm
new file mode 100644 (file)
index 0000000..5390505
--- /dev/null
@@ -0,0 +1,57 @@
+package Imager::Filter::Flines;
+use strict;
+use Imager;
+use vars qw($VERSION @ISA);
+
+BEGIN {
+  $VERSION = "0.01";
+  
+  eval {
+    require XSLoader;
+    XSLoader::load('Imager::Filter::Flines', $VERSION);
+    1;
+  } or do {
+    require DynaLoader;
+    push @ISA, 'DynaLoader';
+    bootstrap Imager::Filter::Flines $VERSION;
+  };
+}
+
+Imager->register_filter(type=>'flines',
+                        callsub => sub { my %hsh = @_; flines($hsh{image}) },
+                        defaults => {},
+                        callseq => [ 'image' ] );
+
+1;
+
+__END__
+
+=head1 NAME
+
+Imager::Filter::Flines - dim alternate lines to emulate a video display
+
+=head1 SYNOPSIS
+
+  use Imager;
+  use Imager::Filter::Flines;
+
+  $img->filter(type=>'flines');
+
+=head1 DESCRIPTION
+
+This is an adaption of the flines dynamically loadable filter
+provided in dynfilt/ in previous releases of Imager.
+
+This filter has no parameters.
+
+=head1 AUTHOR
+
+Original by Arnar M. Hrafnkelsson.
+
+Adapted by Tony Cook <tony@imager.perl.org>
+
+=head1 SEE ALSO
+
+Imager, Imager::Filters.
+
+=cut
diff --git a/Flines/Flines.xs b/Flines/Flines.xs
new file mode 100644 (file)
index 0000000..b3cca4e
--- /dev/null
@@ -0,0 +1,64 @@
+#ifdef __cplusplus
+extern "C" {
+#endif
+#include "EXTERN.h"
+#include "perl.h"
+#include "XSUB.h"
+#include "ppport.h"
+#ifdef __cplusplus
+}
+#endif
+
+#include "imext.h"
+#include "imperl.h"
+
+unsigned char
+static
+saturate(int in) {
+  if (in>255) { return 255; }
+  else if (in>0) return in;
+  return 0;
+}
+
+
+
+void
+flines(i_img *im) {
+  i_color vl;
+  int i,bytes,x,y;
+  int idx;
+  
+  
+  for(y = 0; y < im->ysize; y ++) {
+    for(x = 0; x < im->xsize; x ++ ) {
+      i_gpix(im,x,y,&vl); 
+                       if (!(y%2)) {
+                               float yf = y/(float)im->ysize;
+                               float mf = 1.2-0.8*yf;
+                               vl.rgb.r = saturate(vl.rgb.r*mf);
+                               vl.rgb.g = saturate(vl.rgb.g*mf);
+                               vl.rgb.b = saturate(vl.rgb.b*mf);
+                       } else {
+                               float yf = (im->ysize-y)/(float)im->ysize;
+                               float mf = 1.2-0.8*yf;
+                               vl.rgb.r = saturate(vl.rgb.r*mf);
+                               vl.rgb.g = saturate(vl.rgb.g*mf);
+                               vl.rgb.b = saturate(vl.rgb.b*mf);
+                       } 
+     i_ppix(im,x,y,&vl); 
+    }
+  }
+}
+
+
+DEFINE_IMAGER_CALLBACKS;
+
+MODULE = Imager::Filter::Flines   PACKAGE = Imager::Filter::Flines
+
+void
+flines(im)
+        Imager::ImgRaw im
+
+BOOT:
+        PERL_INITIALIZE_IMAGER_CALLBACKS;
+
diff --git a/Flines/Makefile.PL b/Flines/Makefile.PL
new file mode 100644 (file)
index 0000000..5ca766f
--- /dev/null
@@ -0,0 +1,18 @@
+use ExtUtils::MakeMaker;
+require "../metafile.pl";
+
+my %opts = 
+  (
+   NAME => 'Imager::Filter::Flines',
+   VERSION_FROM => 'Flines.pm',
+   OBJECT => 'Flines.o',
+   INC => '-I..'
+  );
+if ($ExtUtils::MakeMaker::VERSION > 6.06) {
+  $opts{AUTHOR} = 'Tony Cook <tony@imager.perl.org>';
+  $opts{ABSTRACT} = 'Flines Imager filter extension';
+}
+
+WriteMakefile(%opts);
+
+
diff --git a/Flines/t/t00flines.t b/Flines/t/t00flines.t
new file mode 100644 (file)
index 0000000..a43fb75
--- /dev/null
@@ -0,0 +1,23 @@
+#!perl -w
+use strict;
+use blib;
+use lib '../t';
+use Imager;
+use Test::More tests => 3;
+
+BEGIN { use_ok('Imager::Filter::Flines') }
+
+my $im = Imager->new(xsize=>150, ysize=>150);
+
+$im->box(filled=>1, xmin => 70, ymin=>25, xmax =>130, ymax => 125, 
+         color=>'00FF00');
+$im->box(filled=>1, xmin=>20, ymin=>25, xmax=>80, ymax=>125,
+         color => '0000FF');
+$im->arc(x =>75, y=>75, r=>30, color => 'FF0000');
+$im->filter(type=>"conv", coef => [0.1, 0.2, 0.4, 0.2, 0.1]);
+
+ok($im->filter(type=>'flines'),
+   "try filter")
+  or print "# ", $im->errstr, "\n";
+ok($im->write(file => '../testout/t00flines.ppm'),
+   "save result");
index ee7db93e9def06c2d4a66370898ee49befb75963..cdd4da27608376dc88e2a2be30a73fbd87bc0e4b 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -8,6 +8,10 @@ DynTest/DynTest.xs
 DynTest/Makefile.PL
 DynTest/linstretch.c
 DynTest/t/t00dyntest.t
+Flines/Flines.pm
+Flines/Flines.xs
+Flines/Makefile.PL
+Flines/t/t00flines.t
 Imager.pm
 Imager.xs
 MANIFEST
index e00624ef135680a87cff75213bcf416fce4820d4..3fb55bf58d79ea48be13811ec216e7d7738facf5 100644 (file)
@@ -30,6 +30,7 @@ Makefile\.old
 \.o$
 ^testout
 ^blib/
+^Flines/Flines\.c$
 ^Imager\.c$
 ^Mandelbrot/Mandelbrot\.c$
 ^CountColor/CountColor\.c$