Permalink
Browse files

commit changes from draw branch

  • Loading branch information...
Tony Cook
Tony Cook committed Mar 25, 2008
1 parent 8fde3bb commit 9b1ec2b8d2aae25c8864e28af1e7c85e78ca9575
Showing with 3,126 additions and 1,364 deletions.
  1. +23 −0 Changes
  2. +134 −3 Imager.pm
  3. +28 −0 Imager.xs
  4. +3 −1 MANIFEST
  5. +4 −4 Makefile.PL
  6. +211 −0 compose.im
  7. +74 −0 design/draw.pod
  8. +24 −253 draw.c
  9. +30 −521 fills.c
  10. +12 −3 filters.im
  11. +9 −1 fuzz/fuzz.pl
  12. +19 −0 hlines.c
  13. +0 −69 image.c
  14. +16 −1 imager.h
  15. +12 −2 imdatatypes.h
  16. +9 −0 imrender.h
  17. +0 −247 imtoc.perl
  18. +1 −1 lib/Imager/APIRef.pod
  19. +85 −0 lib/Imager/Draw.pod
  20. +4 −88 lib/Imager/Fill.pm
  21. +2 −2 lib/Imager/Fountain.pm
  22. +297 −0 lib/Imager/Preprocess.pm
  23. +98 −4 lib/Imager/Transformations.pod
  24. +232 −0 paste.im
  25. +47 −2 polygon.c
  26. +1,110 −9 render.im
  27. +6 −1 rendert.h
  28. +118 −60 rubthru.im
  29. +123 −28 t/t20fill.t
  30. +164 −2 t/t66paste.t
  31. +217 −62 t/t69rubthru.t
  32. +14 −0 t/x11rubthru.t
View
23 Changes
@@ -6,6 +6,29 @@ Imager 0.63 - unreleased
- the font libraries are now only initialized when needed.
http://rt.cpan.org/Ticket/Display.html?id=28825
+ - moved the imtoc.perl code into Imager::Preprocess
+
+ - paste() and rubthrough() now adapt the source image data to the
+ destination, so you can now safely paste/rubthrough from greyscale
+ images to color images or back, or from alpha channel images to
+ noalpha channels or back.
+ https://rt.cpan.org/Ticket/Display.html?id=30908
+
+ - rubthrough() now falls back to pasting when the source doesn't have
+ an alpha channel. This effectively treats the source as having a
+ max alpha channel, the right thing to do.
+ http://rt.cpan.org/Ticket/Display.html?id=29944
+
+ - re-worked most of the area filling code to use a common set of
+ functions when filling.
+ Corrected normal combine mode.
+ Rewrote most of the combine modes to match the way the SVG draft
+ defines them with respect to a translucent source and destination.
+ Added tests for translucent source and destination.
+ Added tests to check 8-bit/sample and double/sample combines work
+ similarly.
+ https://rt.cpan.org/Ticket/Display.html?id=29879
+
Bug fixes:
- Imager::Matrix2d->translate() now only requires one of the x or y
View
137 Imager.pm
@@ -157,6 +157,19 @@ my %attempted_to_load;
# library keys that are image file formats
my %file_formats = map { $_ => 1 } qw/tiff pnm gif png jpeg raw bmp tga/;
+# image pixel combine types
+my @combine_types =
+ qw/none normal multiply dissolve add subtract diff lighten darken
+ hue saturation value color/;
+my %combine_types;
+@combine_types{@combine_types} = 0 .. $#combine_types;
+$combine_types{mult} = $combine_types{multiply};
+$combine_types{'sub'} = $combine_types{subtract};
+$combine_types{sat} = $combine_types{saturation};
+
+# this will be used to store global defaults at some point
+my %defaults;
+
BEGIN {
require Exporter;
@ISA = qw(Exporter);
@@ -558,6 +571,22 @@ sub _color {
return $result;
}
+sub _combine {
+ my ($self, $combine, $default) = @_;
+
+ if (!defined $combine && ref $self) {
+ $combine = $self->{combine};
+ }
+ defined $combine or $combine = $defaults{combine};
+ defined $combine or $combine = $default;
+
+ if (exists $combine_types{$combine}) {
+ $combine = $combine_types{$combine};
+ }
+
+ return $combine;
+}
+
sub _valid_image {
my ($self) = @_;
@@ -2405,7 +2434,7 @@ sub transform2 {
sub rubthrough {
my $self=shift;
- my %opts=(tx => 0,ty => 0, @_);
+ my %opts= @_;
unless ($self->{IMG}) {
$self->{ERRSTR}='empty input image';
@@ -2422,15 +2451,108 @@ sub rubthrough {
src_maxy => $opts{src}->getheight(),
%opts);
- unless (i_rubthru($self->{IMG}, $opts{src}->{IMG}, $opts{tx}, $opts{ty},
+ my $tx = $opts{tx};
+ defined $tx or $tx = $opts{left};
+ defined $tx or $tx = 0;
+
+ my $ty = $opts{ty};
+ defined $ty or $ty = $opts{top};
+ defined $ty or $ty = 0;
+
+ unless (i_rubthru($self->{IMG}, $opts{src}->{IMG}, $tx, $ty,
$opts{src_minx}, $opts{src_miny},
$opts{src_maxx}, $opts{src_maxy})) {
$self->_set_error($self->_error_as_msg());
return undef;
}
+
return $self;
}
+sub compose {
+ my $self = shift;
+ my %opts =
+ (
+ opacity => 1.0,
+ mask_left => 0,
+ mask_top => 0,
+ @_
+ );
+
+ unless ($self->{IMG}) {
+ $self->_set_error("compose: empty input image");
+ return;
+ }
+
+ unless ($opts{src}) {
+ $self->_set_error("compose: src parameter missing");
+ return;
+ }
+
+ unless ($opts{src}{IMG}) {
+ $self->_set_error("compose: src parameter empty image");
+ return;
+ }
+ my $src = $opts{src};
+
+ my $left = $opts{left};
+ defined $left or $left = $opts{tx};
+ defined $left or $left = 0;
+
+ my $top = $opts{top};
+ defined $top or $top = $opts{ty};
+ defined $top or $top = 0;
+
+ my $src_left = $opts{src_left};
+ defined $src_left or $src_left = $opts{src_minx};
+ defined $src_left or $src_left = 0;
+
+ my $src_top = $opts{src_top};
+ defined $src_top or $src_top = $opts{src_miny};
+ defined $src_top or $src_top = 0;
+
+ my $width = $opts{width};
+ if (!defined $width && defined $opts{src_maxx}) {
+ $width = $opts{src_maxx} - $src_left;
+ }
+ defined $width or $width = $src->getwidth() - $src_left;
+
+ my $height = $opts{height};
+ if (!defined $height && defined $opts{src_maxy}) {
+ $height = $opts{src_maxy} - $src_top;
+ }
+ defined $height or $height = $src->getheight() - $src_top;
+
+ my $combine = $self->_combine($opts{combine}, 'normal');
+
+ if ($opts{mask}) {
+ unless ($opts{mask}{IMG}) {
+ $self->_set_error("compose: mask parameter empty image");
+ return;
+ }
+
+ my $mask_left = $opts{mask_left};
+ defined $mask_left or $mask_left = $opts{mask_minx};
+ defined $mask_left or $mask_left = 0;
+
+ my $mask_top = $opts{mask_top};
+ defined $mask_top or $mask_top = $opts{mask_miny};
+ defined $mask_top or $mask_top = 0;
+
+ i_compose_mask($self->{IMG}, $src->{IMG}, $opts{mask}{IMG},
+ $left, $top, $src_left, $src_top,
+ $mask_left, $mask_top, $width, $height,
+ $combine, $opts{opacity})
+ or return;
+ }
+ else {
+ i_compose($self->{IMG}, $src->{IMG}, $left, $top, $src_left, $src_top,
+ $width, $height, $combine, $opts{opacity})
+ or return;
+ }
+
+ return $self;
+}
sub flip {
my $self = shift;
@@ -3615,6 +3737,10 @@ sub def_guess_type {
return ();
}
+sub combines {
+ return @combine_types;
+}
+
# get the minimum of a list
sub _min {
@@ -3862,7 +3988,8 @@ This example creates a completely black image of width 400 and height
=head1 ERROR HANDLING
-In general a method will return false when it fails, if it does use the errstr() method to find out why:
+In general a method will return false when it fails, if it does use
+the errstr() method to find out why:
=over
@@ -3911,6 +4038,10 @@ circle() - L<Imager::Draw/circle>
colorcount() - L<Imager::Draw/colorcount>
+combines() - L<Imager::Draw/combines>
+
+compose() - L<Imager::Transformations/compose>
+
convert() - L<Imager::Transformations/"Color transformations"> -
transform the color space
View
@@ -1640,6 +1640,34 @@ i_rubthru(im,src,tx,ty,src_minx,src_miny,src_maxx,src_maxy)
int src_maxx
int src_maxy
+undef_int
+i_compose(out, src, out_left, out_top, src_left, src_top, width, height, combine = ic_normal, opacity = 0.0)
+ Imager::ImgRaw out
+ Imager::ImgRaw src
+ int out_left
+ int out_top
+ int src_left
+ int src_top
+ int width
+ int height
+ int combine
+ double opacity
+
+undef_int
+i_compose_mask(out, src, mask, out_left, out_top, src_left, src_top, mask_left, mask_top, width, height, combine = ic_normal, opacity = 0.0)
+ Imager::ImgRaw out
+ Imager::ImgRaw src
+ Imager::ImgRaw mask
+ int out_left
+ int out_top
+ int src_left
+ int src_top
+ int mask_left
+ int mask_top
+ int width
+ int height
+ int combine
+ double opacity
undef_int
i_flipxy(im, direction)
View
@@ -75,6 +75,7 @@ apidocs.perl Build lib/Imager/APIRef.pm
bigtest.perl Library selection tester
bmp.c Reading and writing Windows BMP files
color.c Color translation and handling
+compose.im
conv.im
convert.c
doco.perl
@@ -136,7 +137,6 @@ imio.h
immacros.h
imperl.h
imrender.h Buffer rending engine function declarations
-imtoc.perl Sample size adapter pre-processor
io.c
iolayer.c
iolayer.h
@@ -170,6 +170,7 @@ lib/Imager/ImageTypes.pod
lib/Imager/Inline.pod Using Imager with Inline::C
lib/Imager/LargeSamples.pod Track large sample support
lib/Imager/Matrix2d.pm
+lib/Imager/Preprocess.pm
lib/Imager/Regops.pm
lib/Imager/Test.pm
lib/Imager/Transform.pm
@@ -183,6 +184,7 @@ log.h
map.c
maskimg.c
palimg.c
+paste.im
plug.h
png.c
pnm.c
View
@@ -156,7 +156,7 @@ my @objs = qw(Imager.o draw.o polygon.o image.o io.o iolayer.o
regmach.o trans2.o quant.o error.o convert.o
map.o tags.o palimg.o maskimg.o img16.o rotate.o
bmp.o tga.o color.o fills.o imgdouble.o limits.o hlines.o
- imext.o scale.o rubthru.o render.o);
+ imext.o scale.o rubthru.o render.o paste.o compose.o);
$Recommends{Imager} =
{ 'Parse::RecDescent' => 0 };
@@ -168,7 +168,7 @@ my %opts=(
'DEFINE' => "$OSDEF $CFLAGS",
'INC' => "$lib_cflags $DFLAGS $F_INC",
'OBJECT' => join(' ', @objs, $F_OBJECT),
- clean => { FILES=>'testout meta.tmp rubthru.c scale.c' },
+ clean => { FILES=>'testout meta.tmp rubthru.c scale.c conv.c filters.c gaussian.c render.c rubthru.c' },
PM => gen_PM(),
PREREQ_PM => { 'Test::More' => 0.47 },
);
@@ -236,8 +236,8 @@ sub _im_rule {
(my $c = $im) =~ s/\.im$/.c/;
return <<MAKE;
-$c: $im imtoc.perl
- $perl imtoc.perl $im $c
+$c: $im lib/Imager/Preprocess.pm
+ $perl -Ilib -MImager::Preprocess -epreprocess $im $c
MAKE
Oops, something went wrong.

0 comments on commit 9b1ec2b

Please sign in to comment.