]> git.imager.perl.org - imager.git/blobdiff - Imager.pm
add support for giflib 5.1.0
[imager.git] / Imager.pm
index b15b4058e120c5626a30b26abfdaf1a7de46d7ac..7e61df33af5bbabcfe4ed7c5b4f30415ff20d753 100644 (file)
--- a/Imager.pm
+++ b/Imager.pm
@@ -6,6 +6,7 @@ use IO::File;
 use Scalar::Util;
 use Imager::Color;
 use Imager::Font;
+use Config;
 
 @EXPORT_OK = qw(
                init
@@ -143,7 +144,7 @@ BEGIN {
   if ($ex_version < 5.57) {
     @ISA = qw(Exporter);
   }
-  $VERSION = '0.93';
+  $VERSION = '0.99';
   require XSLoader;
   XSLoader::load(Imager => $VERSION);
 }
@@ -203,12 +204,18 @@ BEGIN {
      callsub => sub { my %hsh=@_; i_hardinvertall($hsh{image}); }
     };
 
-  $filters{autolevels} ={
+  $filters{autolevels_skew} ={
                         callseq => ['image','lsat','usat','skew'],
                         defaults => { lsat=>0.1,usat=>0.1,skew=>0.0 },
                         callsub => sub { my %hsh=@_; i_autolevels($hsh{image},$hsh{lsat},$hsh{usat},$hsh{skew}); }
                        };
 
+  $filters{autolevels} ={
+                        callseq => ['image','lsat','usat'],
+                        defaults => { lsat=>0.1,usat=>0.1 },
+                        callsub => sub { my %hsh=@_; i_autolevels_mono($hsh{image},$hsh{lsat},$hsh{usat}); }
+                       };
+
   $filters{turbnoise} ={
                        callseq => ['image'],
                        defaults => { xo=>0.0,yo=>0.0,scale=>10.0 },
@@ -423,7 +430,7 @@ BEGIN {
 # Non methods
 #
 
-# initlize Imager
+# initialize Imager
 # NOTE: this might be moved to an import override later on
 
 sub import {
@@ -519,6 +526,12 @@ END {
 sub load_plugin {
   my ($filename)=@_;
   my $i;
+
+  if ($^O eq 'android') {
+    require File::Spec;
+    $filename = File::Spec->rel2abs($filename);
+  }
+
   my ($DSO_handle,$str)=DSO_open($filename);
   if (!defined($DSO_handle)) { $Imager::ERRSTR="Couldn't load plugin '$filename'\n"; return undef; }
   my %funcs=DSO_funclist($DSO_handle);
@@ -542,6 +555,11 @@ sub load_plugin {
 sub unload_plugin {
   my ($filename)=@_;
 
+  if ($^O eq 'android') {
+    require File::Spec;
+    $filename = File::Spec->rel2abs($filename);
+  }
+
   if (!$DSOs{$filename}) { $ERRSTR="plugin '$filename' not loaded."; return undef; }
   my ($DSO_handle,$funcref)=@{$DSOs{$filename}};
   for(keys %{$funcref}) {
@@ -1350,12 +1368,11 @@ sub _get_reader_io {
     return io_new_fd($input->{fd});
   }
   elsif ($input->{fh}) {
-    my $fd = fileno($input->{fh});
-    unless (defined $fd) {
+    unless (Scalar::Util::openhandle($input->{fh})) {
       $self->_set_error("Handle in fh option not opened");
       return;
     }
-    return io_new_fd($fd);
+    return Imager::IO->new_fh($input->{fh});
   }
   elsif ($input->{file}) {
     my $file = IO::File->new($input->{file}, "r");
@@ -1405,17 +1422,11 @@ sub _get_writer_io {
     $io = io_new_fd($input->{fd});
   }
   elsif ($input->{fh}) {
-    my $fd = fileno($input->{fh});
-    unless (defined $fd) {
+    unless (Scalar::Util::openhandle($input->{fh})) {
       $self->_set_error("Handle in fh option not opened");
       return;
     }
-    # flush it
-    my $oldfh = select($input->{fh});
-    # flush anything that's buffered, and make sure anything else is flushed
-    $| = 1;
-    select($oldfh);
-    $io = io_new_fd($fd);
+    $io = Imager::IO->new_fh($input->{fh});
   }
   elsif ($input->{file}) {
     my $fh = new IO::File($input->{file},"w+");
@@ -3248,15 +3259,15 @@ sub setpixel {
   else {
     if ($color->isa('Imager::Color')) {
       i_ppix($self->{IMG}, $x, $y, $color)
-       and return;
+       and return "0 but true";
     }
     else {
       i_ppixf($self->{IMG}, $x, $y, $color)
-       and return;
+       and return "0 but true";
     }
-  }
 
-  return $self;
+    return 1;
+  }
 }
 
 sub getpixel {
@@ -4215,6 +4226,46 @@ sub preload {
   eval { require Imager::Font::T1 };
 }
 
+package Imager::IO;
+use IO::Seekable;
+
+sub new_fh {
+  my ($class, $fh) = @_;
+
+  if (tied(*$fh)) {
+    return $class->new_cb
+      (
+       sub {
+        local $\;
+
+        return print $fh $_[0];
+       },
+       sub {
+        my $tmp;
+        my $count = CORE::read $fh, $tmp, $_[1];
+        defined $count
+          or return undef;
+        $count
+          or return "";
+        return $tmp;
+       },
+       sub {
+        if ($_[1] != SEEK_CUR || $_[0] != 0) {
+          unless (CORE::seek $fh, $_[0], $_[1]) {
+            return -1;
+          }
+        }
+
+        return tell $fh;
+       },
+       undef,
+      );
+  }
+  else {
+    return $class->_new_perlio($fh);
+  }
+}
+
 # backward compatibility for %formats
 package Imager::FORMATS;
 use strict;
@@ -4389,6 +4440,10 @@ Overview.
 
 =item *
 
+L<Imager::Install> - installation notes for Imager.
+
+=item *
+
 L<Imager::Tutorial> - a brief introduction to Imager.
 
 =item *
@@ -4455,6 +4510,10 @@ L<Imager::Fountain> - Helper for making gradient profiles.
 
 =item *
 
+L<Imager::IO> - Imager I/O abstraction.
+
+=item *
+
 L<Imager::API> - using Imager's C API
 
 =item *
@@ -5011,17 +5070,19 @@ To browse Imager's git repository:
 
   http://git.imager.perl.org/imager.git
 
-or:
-
-  https://github.com/tonycoz/imager
-
 To clone:
 
   git clone git://git.imager.perl.org/imager.git
 
-or:
+My preference is that patches are provided in the format produced by
+C<git format-patch>, for example, if you made your changes in a branch
+from master you might do:
+
+  git format-patch -k --stdout master >my-patch.txt
 
-  git clone git://github.com/tonycoz/imager.git
+and then attach that to your bug report, either by adding it as an
+attachment in your email client, or by using the Request Tracker
+attachment mechanism.
 
 =head1 AUTHOR
 
@@ -5058,7 +5119,8 @@ L<Affix::Infix2Postfix>(3), L<Parse::RecDescent>(3)
 
 Other perl imaging modules include:
 
-L<GD>(3), L<Image::Magick>(3), L<Graphics::Magick>(3),
+L<GD>(3), L<Image::Magick>(3),
+L<Graphics::Magick|http://www.graphicsmagick.org/perl.html>(3),
 L<Prima::Image>, L<IPA>.
 
 For manipulating image metadata see L<Image::ExifTool>.