]> git.imager.perl.org - imager.git/blobdiff - Imager.pm
various JPEG fixes
[imager.git] / Imager.pm
index 482f6c00ef36c2edc26453e48f65590444e2990c..a091901bde97bc991828ff7bda0f2b604518dcf3 100644 (file)
--- a/Imager.pm
+++ b/Imager.pm
@@ -52,7 +52,6 @@ use Imager::Font;
                i_haar
                i_count_colors
 
-
                i_gaussian
                i_conv
 
@@ -226,6 +225,39 @@ BEGIN {
                         defaults => { },
                         callsub => sub { my %hsh = @_; i_gaussian($hsh{image}, $hsh{stddev}); },
                        };
+  $filters{mosaic} =
+    {
+     callseq => [ qw(image size) ],
+     defaults => { size => 20 },
+     callsub => sub { my %hsh = @_; i_mosaic($hsh{image}, $hsh{size}) },
+    };
+  $filters{bumpmap} =
+    {
+     callseq => [ qw(image bump elevation lightx lighty st) ],
+     defaults => { elevation=>0, st=> 2 },
+     callsub => sub { 
+       my %hsh = @_;
+       i_bumpmap($hsh{image}, $hsh{bump}{IMG}, $hsh{elevation},
+                 $hsh{lightx}, $hsh{lighty}, $hsh{st});
+     },
+    };
+  $filters{postlevels} =
+    {
+     callseq  => [ qw(image levels) ],
+     defaults => { levels => 10 },
+     callsub  => sub { my %hsh = @_; i_postlevels($hsh{image}, $hsh{levels}); },
+    };
+  $filters{watermark} =
+    {
+     callseq  => [ qw(image wmark tx ty pixdiff) ],
+     defaults => { pixdiff=>10, tx=>0, ty=>0 },
+     callsub  => 
+     sub { 
+       my %hsh = @_; 
+       i_watermark($hsh{image}, $hsh{wmark}{IMG}, $hsh{tx}, $hsh{ty}, 
+                   $hsh{pixdiff}); 
+     },
+    };
 
   $FORMATGUESS=\&def_guess_type;
 }
@@ -332,7 +364,6 @@ sub new {
   return $self;
 }
 
-
 # Copy an entire image with no changes 
 # - if an image has magic the copy of it will not be magical
 
@@ -703,7 +734,7 @@ sub read {
   # yes the code isn't here yet - next week maybe?
   # Next week?  Are you high or something?  That comment
   # has been there for half a year dude.
-
+  # Look, i just work here, ok?
 
   if (!$input{type} and $input{file}) {
     $input{type}=$FORMATGUESS->($input{file});
@@ -712,7 +743,7 @@ sub read {
     $self->{ERRSTR}='format not supported'; return undef;
   }
 
-  my %iolready=(jpeg=>1, png=>1, tiff=>1, pnm=>1, raw=>1);
+  my %iolready=(jpeg=>1, png=>1, tiff=>1, pnm=>1, raw=>1, bmp=>1);
 
   if ($iolready{$input{type}}) {
     # Setup data source
@@ -754,6 +785,15 @@ sub read {
       $self->{DEBUG} && print "loading a png file\n";
     }
 
+    if ( $input{type} eq 'bmp' ) {
+      $self->{IMG}=i_readbmp_wiol( $IO );
+      if ( !defined($self->{IMG}) ) {
+       $self->{ERRSTR}='unable to read bmp image';
+       return undef;
+      }
+      $self->{DEBUG} && print "loading a bmp file\n";
+    }
+
     if ( $input{type} eq 'raw' ) {
       my %params=(datachannels=>3,storechannels=>3,interleave=>1,%input);
 
@@ -779,7 +819,6 @@ sub read {
 
     # Old code for reference while changing the new stuff
 
-
     if (!$input{type} and $input{file}) {
       $input{type}=$FORMATGUESS->($input{file});
     }
@@ -837,29 +876,18 @@ sub read {
       }
       $self->{DEBUG} && print "loading a gif file\n";
     }
-
-    if ( $input{type} eq 'jpeg' ) {
-      if ( !i_writejpeg_wiol($self->{IMG}, $IO, $input{jpegquality})) {
-       $self->{ERRSTR}='unable to write jpeg image'; 
-       return undef;
-      }
-      $self->{DEBUG} && print "writing a jpeg file\n";
-    }
-
   }
   return $self;
 }
 
-
 # Write an image to file
-
 sub write {
   my $self = shift;
   my %input=(jpegquality=>75, gifquant=>'mc', lmdither=>6.0, lmfixed=>[], 
             fax_fine=>1, @_);
   my ($fh, $rc, $fd, $IO);
 
-  my %iolready=( tiff=>1, raw=>1, png=>1, pnm=>1 ); # this will be SO MUCH BETTER once they are all in there
+  my %iolready=( tiff=>1, raw=>1, png=>1, pnm=>1, bmp=>1, jpeg=>1 ); # this will be SO MUCH BETTER once they are all in there
 
   unless ($self->{IMG}) { $self->{ERRSTR}='empty input image'; return undef; }
 
@@ -915,6 +943,18 @@ sub write {
        return undef;
       }
       $self->{DEBUG} && print "writing a png file\n";
+    } elsif ( $input{type} eq 'jpeg' ) {
+      if ( !i_writejpeg_wiol($self->{IMG}, $IO, $input{jpegquality})) {
+       $self->{ERRSTR}='unable to write jpeg image'; 
+       return undef;
+      }
+      $self->{DEBUG} && print "writing a jpeg file\n";
+    } elsif ( $input{type} eq 'bmp' ) {
+      if ( !i_writebmp_wiol($self->{IMG}, $IO) ) {
+       $self->{ERRSTR}='unable to write bmp image';
+       return undef;
+      }
+      $self->{DEBUG} && print "writing a bmp file\n";
     }
 
     if (exists $input{'data'}) {
@@ -927,7 +967,6 @@ sub write {
     }
     return $self;
   } else {
-
     if ( $input{type} eq 'gif' ) {
       if (not $input{gifplanes}) {
        my $gp;
@@ -1852,6 +1891,7 @@ sub def_guess_type {
   return 'jpeg' if ($ext =~ m/^jpe?g$/);
   return 'pnm'  if ($ext =~ m/^p[pgb]m$/);
   return 'png'  if ($ext eq "png");
+  return 'bmp'  if ($ext eq "bmp" || $ext eq "dib");
   return 'gif'  if ($ext eq "gif");
   return ();
 }
@@ -2781,14 +2821,17 @@ source.
 
   Filter          Arguments
   autolevels      lsat(0.1) usat(0.1) skew(0)
+  bumpmap         bump elevation(0) lightx lighty st(2)
   contrast        intensity
   conv            coef
   gaussian        stddev
   gradgen         xo yo colors dist
   hardinvert
   noise           amount(3) subtype(0)
+  postlevels      levels(10)
   radnoise        xo(100) yo(100) ascale(17.0) rscale(0.02)
   turbnoise       xo(0.0) yo(0.0) scale(10.0)
+  watermark       wmark pixdiff(10) tx(0) ty(0)
 
 The default values are in parenthesis.  All parameters must have some
 value but if a parameter has a default value it may be omitted when
@@ -2805,6 +2848,12 @@ cover the whole possible range for the channel.  I<lsat> and I<usat>
 truncate the range by the specified fraction at the top and bottom of
 the range respectivly..
 
+=item bumpmap
+
+uses the channel I<elevation> image I<bump> as a bumpmap on your
+image, with the light at (I<lightx>, I<lightty>), with a shadow length
+of I<st>.
+
 =item contrast
 
 scales each channel by I<intensity>.  Values of I<intensity> < 1.0
@@ -2847,15 +2896,25 @@ renders radiant Perlin turbulent noise.  The centre of the noise is at
 (I<xo>, I<yo>), I<ascale> controls the angular scale of the noise ,
 and I<rscale> the radial scale, higher numbers give more detail.
 
+=item postlevels
+
+alters the image to have only I<levels> distinct level in each
+channel.
+
 =item turbnoise
 
 renders Perlin turbulent noise.  (I<xo>, I<yo>) controls the origin of
 the noise, and I<scale> the scale of the noise, with lower numbers
 giving more detail.
 
+=item watermark
+
+applies I<wmark> as a watermark on the image with strength I<pixdiff>,
+with an origin at (I<tx>, I<ty>)
+
 =back
 
-A demonstration of the the filters can be found at:
+A demonstration of most of the filters can be found at:
 
   http://www.develop-help.com/imager/filters.html
 
@@ -3419,7 +3478,7 @@ the first block of the first gif comment before each image.
 Where applicable, the ("name") is the name of that field from the GIF89 
 standard.
 
-The following ares are set in a TIFF image when read, and can be set
+The following tags are set in a TIFF image when read, and can be set
 to control output:
 
 =over
@@ -3431,6 +3490,20 @@ the i_aspect_only tag is non-zero.
 
 =back
 
+The following tags are set when reading a Windows BMP file is read:
+
+=over
+
+=item bmp_compression
+
+The type of compression, if any.
+
+=item bmp_important_colors
+
+The number of important colors as defined by the writer of the image.
+
+=back
+
 Some standard tags will be implemented as time goes by:
 
 =over