From: Arnar Mar Hrafnkelsson Date: Fri, 4 May 2001 07:15:09 +0000 (+0000) Subject: Added flip() and docs to Imager.pm and i_flipxy() to image.{c,h}. X-Git-Tag: Imager-0.48^2~707 X-Git-Url: http://git.imager.perl.org/imager.git/commitdiff_plain/142c26ffba0af105e1b0d1dfd2cf63778b1f2ef3 Added flip() and docs to Imager.pm and i_flipxy() to image.{c,h}. --- diff --git a/Changes b/Changes index 77288c54..6556d1ab 100644 --- a/Changes +++ b/Changes @@ -379,7 +379,7 @@ Revision history for Perl extension Imager. Imager.xs, Imager.pm - each of the image formats now have their own test file, extracted from t10formats.t, usually with som extra tests - + - Added flip() and docs to Imager.pm and i_flipxy to image.c. ~~~~~~~~~~~~~^ ^ ^~~~~~~~~~~~~~ diff --git a/Imager.pm b/Imager.pm index 2095b9a7..df7c464c 100644 --- a/Imager.pm +++ b/Imager.pm @@ -993,6 +993,18 @@ sub rubthrough { } +sub flip { + my $self = shift; + my %opts = @_; + my %xlate = (x=>0, y=>1, xy=>2, yx=>2); + my $dir; + return () unless defined $opts{'dir'} and defined $xlate{$opts{'dir'}}; + $dir = $xlate{$opts{'dir'}}; + return $self if i_flipxy($self->{IMG}, $dir); + return (); +} + + # These two are supported for legacy code only @@ -1887,7 +1899,6 @@ the function return undef. Examples: =head2 Drawing Methods IMPLEMENTATION MORE OR LESS DONE CHECK THE TESTS - DOCUMENTATION OF THIS SECTION OUT OF SYNC It is possible to draw with graphics primitives onto images. Such @@ -1994,10 +2005,21 @@ To copy an image to onto another image use the C method. That copies the entire C<$logo> image onto the C<$dest> image so that the upper left corner of the C<$logo> image is at (40,20). -=head2 Blending Images - -To put an image or a part of an image directly into another it is -best to call the C method on the image you want to add to. + +=head2 Flipping images + +An inplace horizontal or vertical flip is possible by calling the +C method. If the original is to be preserved it's possible +to make a copy first. + + $img->flip(dir=>"x"); # horizontal flip + $img->flip(dir=>"xy"); # vertical and horizontal flip + $nimg = $img->copy->flip(dir=>"y"); # make a copy and flip the copy vertically + + +=head2 Blending Images To put an image or a part of an image directly +into another it is best to call the C method on the image you +want to add to. $img->paste(img=>$srcimage,left=>30,top=>50); diff --git a/Imager.xs b/Imager.xs index 6cd95690..71390c9f 100644 --- a/Imager.xs +++ b/Imager.xs @@ -745,6 +745,11 @@ i_rubthru(im,src,tx,ty) int tx int ty +undef_int +i_flipxy(im, direction) + Imager::ImgRaw im + int direction + void i_gaussian(im,stdev) diff --git a/image.c b/image.c index dbbf1be2..b83be162 100644 --- a/image.c +++ b/image.c @@ -32,6 +32,7 @@ Some of these functions are internal. #define XAXIS 0 #define YAXIS 1 +#define XYAXIS 2 #define minmax(a,b,i) ( ((a>=i)?a: ( (b<=i)?b:i )) ) @@ -252,8 +253,8 @@ i_img_empty(i_img *im,int x,int y) { Re-new image reference im - Image pointer - x - xsize of destination image - y - ysize of destination image + x - xsize of destination image + y - ysize of destination image ch - number of channels =cut @@ -595,6 +596,7 @@ unmodified. =cut */ + void i_rubthru(i_img *im,i_img *src,int tx,int ty) { i_color pv,orig,dest; @@ -624,6 +626,94 @@ i_rubthru(i_img *im,i_img *src,int tx,int ty) { } } + +/* +=item i_flipxy(im, axis) + +Flips the image inplace around the axis specified. +Returns 0 if parameters are invalid. + + im - Image pointer + axis - 0 = x, 1 = y, 2 = both + +=cut +*/ + +undef_int +i_flipxy(i_img *im, int direction) { + int x, x2, y, y2, xm, ym; + int xs = im->xsize; + int ys = im->ysize; + + mm_log((1, "i_flipxy(im %p, direction %d)\n", im, direction )); + + if (!im) return 0; + + switch (direction) { + case XAXIS: /* Horizontal flip */ + xm = xs/2; + ym = ys; + for(y=0; y