r47313 - in /branches/upstream/libimager-perl/current: Changes Imager.pm Imager.xs META.yml Makefile.PL conv.im fills.c imager.h lib/Imager/Fill.pm lib/Imager/Filters.pod lib/Imager/Test.pm t/t20fill.t t/t61filters.t
jawnsy-guest at users.alioth.debian.org
jawnsy-guest at users.alioth.debian.org
Mon Nov 16 18:13:13 UTC 2009
Author: jawnsy-guest
Date: Mon Nov 16 18:13:07 2009
New Revision: 47313
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=47313
Log:
[svn-upgrade] Integrating new upstream version, libimager-perl (0.71)
Modified:
branches/upstream/libimager-perl/current/Changes
branches/upstream/libimager-perl/current/Imager.pm
branches/upstream/libimager-perl/current/Imager.xs
branches/upstream/libimager-perl/current/META.yml
branches/upstream/libimager-perl/current/Makefile.PL
branches/upstream/libimager-perl/current/conv.im
branches/upstream/libimager-perl/current/fills.c
branches/upstream/libimager-perl/current/imager.h
branches/upstream/libimager-perl/current/lib/Imager/Fill.pm
branches/upstream/libimager-perl/current/lib/Imager/Filters.pod
branches/upstream/libimager-perl/current/lib/Imager/Test.pm
branches/upstream/libimager-perl/current/t/t20fill.t
branches/upstream/libimager-perl/current/t/t61filters.t
Modified: branches/upstream/libimager-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libimager-perl/current/Changes?rev=47313&op=diff
==============================================================================
--- branches/upstream/libimager-perl/current/Changes (original)
+++ branches/upstream/libimager-perl/current/Changes Mon Nov 16 18:13:07 2009
@@ -1,4 +1,20 @@
Imager release history. Older releases can be found in Changes.old
+
+Imager 0.71 - 16 Nov 2009
+===========
+
+ - add the opacity fill type - an adaptor that modifies the opacity of
+ another fill.
+
+Bug fixes:
+
+ - the conv filter now enforces that the sum of the coefficients is
+ non-zero. Also, rather than skipping pixels off the edge off the
+ edge of the image, the closest edge pixel is used. Previously
+ dividing by the zero sum of coefficients could cause invalid
+ results or runtime exceptions.
+ Thanks to David Cantrell's Alpha-NetBSD CPAN test box for revealing
+ this bug.
Imager 0.70 - 21 Sep 2009
===========
Modified: branches/upstream/libimager-perl/current/Imager.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libimager-perl/current/Imager.pm?rev=47313&op=diff
==============================================================================
--- branches/upstream/libimager-perl/current/Imager.pm (original)
+++ branches/upstream/libimager-perl/current/Imager.pm Mon Nov 16 18:13:07 2009
@@ -173,7 +173,7 @@
BEGIN {
require Exporter;
@ISA = qw(Exporter);
- $VERSION = '0.70';
+ $VERSION = '0.71';
eval {
require XSLoader;
XSLoader::load(Imager => $VERSION);
@@ -243,11 +243,17 @@
callsub => sub { my %hsh=@_; i_radnoise($hsh{image},$hsh{xo},$hsh{yo},$hsh{rscale},$hsh{ascale}); }
};
- $filters{conv} ={
- callseq => ['image', 'coef'],
- defaults => { },
- callsub => sub { my %hsh=@_; i_conv($hsh{image},$hsh{coef}); }
- };
+ $filters{conv} =
+ {
+ callseq => ['image', 'coef'],
+ defaults => { },
+ callsub =>
+ sub {
+ my %hsh=@_;
+ i_conv($hsh{image},$hsh{coef})
+ or die Imager->_error_as_msg() . "\n";
+ }
+ };
$filters{gradgen} =
{
Modified: branches/upstream/libimager-perl/current/Imager.xs
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libimager-perl/current/Imager.xs?rev=47313&op=diff
==============================================================================
--- branches/upstream/libimager-perl/current/Imager.xs (original)
+++ branches/upstream/libimager-perl/current/Imager.xs Mon Nov 16 18:13:07 2009
@@ -1756,27 +1756,26 @@
float stdev
double scale
-void
-i_conv(im,pcoef)
- Imager::ImgRaw im
- PREINIT:
- float* coeff;
- int len;
- AV* av;
- SV* sv1;
- int i;
- PPCODE:
- if (!SvROK(ST(1))) croak("Imager: Parameter 1 must be a reference to an array\n");
- if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 must be a reference to an array\n");
- av=(AV*)SvRV(ST(1));
- len=av_len(av)+1;
- coeff=mymalloc( len*sizeof(float) );
- for(i=0;i<len;i++) {
- sv1=(*(av_fetch(av,i,0)));
- coeff[i]=(float)SvNV(sv1);
- }
- i_conv(im,coeff,len);
- myfree(coeff);
+int
+i_conv(im,coef)
+ Imager::ImgRaw im
+ AV *coef
+ PREINIT:
+ double* c_coef;
+ int len;
+ SV* sv1;
+ int i;
+ CODE:
+ len = av_len(coef) + 1;
+ c_coef=mymalloc( len * sizeof(double) );
+ for(i = 0; i < len; i++) {
+ sv1 = (*(av_fetch(coef, i, 0)));
+ c_coef[i] = (double)SvNV(sv1);
+ }
+ RETVAL = i_conv(im, c_coef, len);
+ myfree(c_coef);
+ OUTPUT:
+ RETVAL
Imager::ImgRaw
i_convert(src, avmain)
@@ -3380,6 +3379,11 @@
OUTPUT:
RETVAL
+Imager::FillHandle
+i_new_fill_opacity(other_fill, alpha_mult)
+ Imager::FillHandle other_fill
+ double alpha_mult
+
void
i_errors()
PREINIT:
Modified: branches/upstream/libimager-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libimager-perl/current/META.yml?rev=47313&op=diff
==============================================================================
--- branches/upstream/libimager-perl/current/META.yml (original)
+++ branches/upstream/libimager-perl/current/META.yml Mon Nov 16 18:13:07 2009
@@ -1,6 +1,6 @@
--- #YAML:1.0
name: Imager
-version: 0.70
+version: 0.71
abstract: Perl extension for Generating 24 bit Images
author:
- Tony Cook <tony at imager.perl.org>, Arnar M. Hrafnkelsson
Modified: branches/upstream/libimager-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libimager-perl/current/Makefile.PL?rev=47313&op=diff
==============================================================================
--- branches/upstream/libimager-perl/current/Makefile.PL (original)
+++ branches/upstream/libimager-perl/current/Makefile.PL Mon Nov 16 18:13:07 2009
@@ -944,6 +944,12 @@
Add to the include search path
--libpath dir
Add to the library search path
+ --coverage
+ Build for coverage testing.
+ --assert
+ Build with assertions active.
+ --noexif
+ Disable EXIF parsing.
EOS
exit 1;
Modified: branches/upstream/libimager-perl/current/conv.im
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libimager-perl/current/conv.im?rev=47313&op=diff
==============================================================================
--- branches/upstream/libimager-perl/current/conv.im (original)
+++ branches/upstream/libimager-perl/current/conv.im Mon Nov 16 18:13:07 2009
@@ -1,4 +1,5 @@
#include "imager.h"
+#include "imageri.h"
/*
General convolution for 2d decoupled filters
@@ -11,72 +12,87 @@
(since the filter is even);
*/
-void
-i_conv(i_img *im,const float *coeff,int len) {
- int i,l,c,ch,center;
+int
+i_conv(i_img *im, const double *coeff,int len) {
+ int xo, yo; /* output pixel co-ordinate */
+ int c, ch, center;
double pc;
- double res[11];
+ double res[MAXCHANNELS];
i_img *timg;
mm_log((1,"i_conv(im %p, coeff %p, len %d)\n",im,coeff,len));
+ i_clear_error();
+ center=(len-1)/2;
+
+ pc = 0;
+ for (c = 0; c < len; ++c)
+ pc += coeff[c];
+
+ if (pc == 0) {
+ i_push_error(0, "sum of coefficients is zero");
+ return 0;
+ }
+
timg = i_sametype(im, im->xsize, im->ysize);
-
- center=(len-1)/2;
#code im->bits <= 8
IM_COLOR rcolor;
/* don't move the calculation of pc up here, it depends on which pixels
are readable */
- for(l=0;l<im->ysize;l++) {
- for(i=0;i<im->xsize;i++) {
- pc=0.0;
- for(ch=0;ch<im->channels;ch++)
- res[ch]=0;
- for(c=0;c<len;c++)
- if (IM_GPIX(im,i+c-center,l,&rcolor)!=-1) {
- for(ch=0;ch<im->channels;ch++)
- res[ch] += (rcolor.channel[ch])*coeff[c];
- pc+=coeff[c];
+ for(yo = 0; yo < im->ysize; yo++) {
+ for(xo = 0; xo < im->xsize; xo++) {
+ for(ch = 0;ch < im->channels; ch++)
+ res[ch] = 0;
+ for(c = 0;c < len; c++) {
+ int xi = xo + c - center;
+ if (xi < 0)
+ xi = 0;
+ else if (xi >= im->xsize)
+ xi = im->xsize - 1;
+
+ if (IM_GPIX(im, xi, yo, &rcolor)!=-1) {
+ for(ch = 0; ch < im->channels; ch++)
+ res[ch] += (rcolor.channel[ch]) *coeff[c];
}
- for(ch=0;ch<im->channels;ch++) {
- double temp = res[ch]/pc;
+ }
+ im_assert(pc != 0);
+ for(ch = 0; ch < im->channels; ch++) {
+ double temp = res[ch] / pc;
rcolor.channel[ch] =
temp < 0 ? 0 : temp > IM_SAMPLE_MAX ? IM_SAMPLE_MAX : (IM_SAMPLE_T)temp;
}
- IM_PPIX(timg,i,l,&rcolor);
+ IM_PPIX(timg, xo, yo, &rcolor);
}
}
- for(l=0;l<im->xsize;l++) {
- for(i=0;i<im->ysize;i++) {
- pc=0.0;
- for(ch=0;ch<im->channels;ch++) res[ch]=0;
- for(c=0;c<len;c++) {
- if (IM_GPIX(timg,l,i+c-center,&rcolor)!=-1) {
- for(ch=0;ch<im->channels;ch++)
- res[ch] += (rcolor.channel[ch])*coeff[c];
- pc+=coeff[c];
+ for(xo = 0; xo < im->xsize; xo++) {
+ for(yo = 0;yo < im->ysize; yo++) {
+ for(ch = 0; ch < im->channels; ch++)
+ res[ch] = 0;
+ for(c = 0; c < len; c++) {
+ int yi = yo + c - center;
+ if (yi < 0)
+ yi = 0;
+ else if (yi >= im->ysize)
+ yi = im->ysize - 1;
+ if (IM_GPIX(timg, xo, yi, &rcolor) != -1) {
+ for(ch = 0;ch < im->channels; ch++)
+ res[ch] += (rcolor.channel[ch]) * coeff[c];
}
}
- for(ch=0;ch<im->channels;ch++) {
- double temp = res[ch]/pc;
- rcolor.channel[ch]=
+ im_assert(pc != 0);
+ for(ch = 0;ch < im->channels; ch++) {
+ double temp = res[ch] / pc;
+ rcolor.channel[ch] =
temp < 0 ? 0 : temp > IM_SAMPLE_MAX ? IM_SAMPLE_MAX : (IM_SAMPLE_T)temp;
}
- IM_PPIX(im,l,i,&rcolor);
+ IM_PPIX(im, xo, yo,&rcolor);
}
}
#/code
i_img_destroy(timg);
+
+ return 1;
}
-
-
-
-
-
-
-
-
-
Modified: branches/upstream/libimager-perl/current/fills.c
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libimager-perl/current/fills.c?rev=47313&op=diff
==============================================================================
--- branches/upstream/libimager-perl/current/fills.c (original)
+++ branches/upstream/libimager-perl/current/fills.c Mon Nov 16 18:13:07 2009
@@ -17,6 +17,7 @@
fill = i_new_fill_hatchf(&fc1, &fc2, combine, hatch, cust_hash, dx, dy);
fill = i_new_fill_hatch(&c1, &c2, combine, hatch, cust_hash, dx, dy);
fill = i_new_fill_image(im, matrix, xoff, yoff, combine);
+ fill = i_new_fill_opacity(fill, alpha_mult);
i_fill_destroy(fill);
=head1 DESCRIPTION
@@ -528,6 +529,38 @@
return &fill->base;
}
+static void fill_opacity(i_fill_t *fill, int x, int y, int width, int channels,
+ i_color *data);
+static void fill_opacityf(i_fill_t *fill, int x, int y, int width, int channels,
+ i_fcolor *data);
+
+struct i_fill_opacity_t {
+ i_fill_t base;
+ i_fill_t *other_fill;
+ double alpha_mult;
+};
+
+static struct i_fill_opacity_t
+opacity_fill_proto =
+ {
+ fill_opacity,
+ fill_opacityf,
+ NULL
+ };
+
+i_fill_t *
+i_new_fill_opacity(i_fill_t *base_fill, double alpha_mult) {
+ struct i_fill_opacity_t *fill = mymalloc(sizeof(*fill));
+ *fill = opacity_fill_proto;
+
+ fill->base.combine = base_fill->combine;
+ fill->base.combinef = base_fill->combinef;
+
+ fill->other_fill = base_fill;
+ fill->alpha_mult = alpha_mult;
+
+ return &fill->base;
+}
#define T_SOLID_FILL(fill) ((i_fill_solid_t *)(fill))
@@ -901,6 +934,45 @@
i_adapt_fcolors(want_channels, f->src->channels, data, width);
}
+static void
+fill_opacity(i_fill_t *fill, int x, int y, int width, int channels,
+ i_color *data) {
+ struct i_fill_opacity_t *f = (struct i_fill_opacity_t *)fill;
+ int alpha_chan = channels-1; /* channels is always 2 or 4 */
+ i_color *datap = data;
+
+ (f->other_fill->f_fill_with_color)(f->other_fill, x, y, width, channels, data);
+ while (width--) {
+ double new_alpha = datap->channel[alpha_chan] * f->alpha_mult;
+ if (new_alpha < 0)
+ datap->channel[alpha_chan] = 0;
+ else if (new_alpha > 255)
+ datap->channel[alpha_chan] = 255;
+ else datap->channel[alpha_chan] = (int)(new_alpha + 0.5);
+
+ ++datap;
+ }
+}
+static void
+fill_opacityf(i_fill_t *fill, int x, int y, int width, int channels,
+ i_fcolor *data) {
+ struct i_fill_opacity_t *f = (struct i_fill_alpha_t *)fill;
+ int alpha_chan = channels-1; /* channels is always 2 or 4 */
+ i_fcolor *datap = data;
+
+ (f->other_fill->f_fill_with_fcolor)(f->other_fill, x, y, width, channels, data);
+
+ while (width--) {
+ double new_alpha = datap->channel[alpha_chan] * f->alpha_mult;
+ if (new_alpha < 0)
+ datap->channel[alpha_chan] = 0;
+ else if (new_alpha > 1.0)
+ datap->channel[alpha_chan] = 1.0;
+ else datap->channel[alpha_chan] = new_alpha;
+
+ ++datap;
+ }
+}
/*
=back
Modified: branches/upstream/libimager-perl/current/imager.h
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libimager-perl/current/imager.h?rev=47313&op=diff
==============================================================================
--- branches/upstream/libimager-perl/current/imager.h (original)
+++ branches/upstream/libimager-perl/current/imager.h Mon Nov 16 18:13:07 2009
@@ -155,6 +155,7 @@
const unsigned char *cust_hatch, int dx, int dy);
extern i_fill_t *
i_new_fill_image(i_img *im, const double *matrix, int xoff, int yoff, int combine);
+extern i_fill_t *i_new_fill_opacity(i_fill_t *, double alpha_mult);
extern void i_fill_destroy(i_fill_t *fill);
float i_gpix_pch(i_img *im,int x,int y,int ch);
@@ -205,7 +206,7 @@
/* image processing functions */
int i_gaussian (i_img *im, double stdev);
-void i_conv (i_img *im,const float *coeff,int len);
+int i_conv (i_img *im,const double *coeff,int len);
void i_unsharp_mask(i_img *im, double stddev, double scale);
/* colour manipulation */
Modified: branches/upstream/libimager-perl/current/lib/Imager/Fill.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libimager-perl/current/lib/Imager/Fill.pm?rev=47313&op=diff
==============================================================================
--- branches/upstream/libimager-perl/current/lib/Imager/Fill.pm (original)
+++ branches/upstream/libimager-perl/current/lib/Imager/Fill.pm Mon Nov 16 18:13:07 2009
@@ -125,6 +125,35 @@
$hsh{yoff}, $hsh{combine});
$self->{DEPS} = [ $hsh{image}{IMG} ];
}
+ elsif (defined $hsh{type} && $hsh{type} eq "opacity") {
+ my $other_fill = delete $hsh{other};
+ unless (defined $other_fill) {
+ Imager->_set_error("'other' parameter required to create opacity fill");
+ return;
+ }
+ unless (ref $other_fill &&
+ eval { $other_fill->isa("Imager::Fill") }) {
+ # try to auto convert to a fill object
+ if (ref $other_fill && $other_fill =~ /HASH/) {
+ $other_fill = Imager::Fill->new(%$other_fill)
+ or return;
+ }
+ else {
+ undef $other_fill;
+ }
+ unless ($other_fill) {
+ Imager->_set_error("'other' parameter must be an Imager::Fill object to create an opacity fill");
+ return;
+ }
+ }
+
+ my $raw_fill = $other_fill->{fill};
+ my $opacity = delete $hsh{opacity};
+ defined $opacity or $opacity = 0.5; # some sort of default
+ $self->{fill} =
+ Imager::i_new_fill_opacity($raw_fill, $opacity);
+ $self->{DEPS} = [ $other_fill ]; # keep reference to old fill and its deps
+ }
else {
$Imager::ERRSTR = "No fill type specified";
warn "No fill type!";
@@ -158,6 +187,8 @@
dx=>$dx, dy=>$dy);
my $fill3 = Imager::Fill->new(fountain=>$type, ...);
my $fill4 = Imager::Fill->new(image=>$img, ...);
+ my $fill5 = Imager::Fill->new(type => "opacity", other => $fill,
+ opacity => ...);
=head1 DESCRIPTION
@@ -341,6 +372,36 @@
The matrix parameter will significantly slow down the fill.
+=head2 Opacity modification fill
+
+ my $fill = Imager::Fill->new(type => "opacity",
+ other => $fill, opacity => 0.25);
+
+This can be used to make a fill that is a more translucent or opaque
+version of an existing fill. This is intended for use where you
+receive a fill object as a parameter and need to change the opacity.
+
+Parameters:
+
+=over
+
+=item *
+
+type => "opacity" - Required
+
+=item *
+
+other - the fill to produce a modified version of. This must be an
+Imager::Fill object. Required.
+
+=item *
+
+opacity - multiplier for the source fill opacity. Default: 0.5.
+
+=back
+
+The source fill's combine mode is used.
+
=head1 OTHER METHODS
=over
Modified: branches/upstream/libimager-perl/current/lib/Imager/Filters.pod
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libimager-perl/current/lib/Imager/Filters.pod?rev=47313&op=diff
==============================================================================
--- branches/upstream/libimager-perl/current/lib/Imager/Filters.pod (original)
+++ branches/upstream/libimager-perl/current/lib/Imager/Filters.pod Mon Nov 16 18:13:07 2009
@@ -196,6 +196,10 @@
# blur
$img->filter(type=>"conv", coef=>[ 1, 2, 1 ])
+ or die $img->errstr;
+
+ # error
+ $img->filter(type=>"conv", coef=>[ -0.5, 1, -0.5 ])
or die $img->errstr;
=item fountain
@@ -694,6 +698,6 @@
=head1 REVISION
-$Revision: 1330 $
+$Revision: 1643 $
=cut
Modified: branches/upstream/libimager-perl/current/lib/Imager/Test.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libimager-perl/current/lib/Imager/Test.pm?rev=47313&op=diff
==============================================================================
--- branches/upstream/libimager-perl/current/lib/Imager/Test.pm (original)
+++ branches/upstream/libimager-perl/current/lib/Imager/Test.pm Mon Nov 16 18:13:07 2009
@@ -127,10 +127,10 @@
&& $ca == $alpha, $comment)) {
$builder->diag(<<END_DIAG);
Color mismatch:
- Red: $red vs $cr
-Green: $green vs $cg
- Blue: $blue vs $cb
-Alpha: $alpha vs $ca
+ Red: $cr vs $red
+Green: $cg vs $green
+ Blue: $cb vs $blue
+Alpha: $ca vs $alpha
END_DIAG
return;
}
@@ -168,10 +168,10 @@
&& abs($ca - $alpha) <= $mindiff, $comment)) {
$builder->diag(<<END_DIAG);
Color mismatch:
- Red: $red vs $cr
-Green: $green vs $cg
- Blue: $blue vs $cb
-Alpha: $alpha vs $ca
+ Red: $cr vs $red
+Green: $cg vs $green
+ Blue: $cb vs $blue
+Alpha: $ca vs $alpha
END_DIAG
return;
}
Modified: branches/upstream/libimager-perl/current/t/t20fill.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libimager-perl/current/t/t20fill.t?rev=47313&op=diff
==============================================================================
--- branches/upstream/libimager-perl/current/t/t20fill.t (original)
+++ branches/upstream/libimager-perl/current/t/t20fill.t Mon Nov 16 18:13:07 2009
@@ -1,11 +1,11 @@
#!perl -w
use strict;
-use Test::More tests => 129;
+use Test::More tests => 148;
use Imager ':handy';
use Imager::Fill;
use Imager::Color::Float;
-use Imager::Test qw(is_image);
+use Imager::Test qw(is_image is_color4 is_fcolor4);
use Config;
Imager::init_log("testout/t20fill.log", 1);
@@ -466,6 +466,121 @@
}
}
+{ # alpha modifying fills
+ { # 8-bit/sample
+ my $base_img = Imager->new(xsize => 4, ysize => 2, channels => 4);
+ $base_img->setscanline
+ (
+ x => 0,
+ y => 0,
+ pixels =>
+ [
+ map Imager::Color->new($_),
+ qw/FF000020 00FF0080 00008040 FFFF00FF/,
+ ],
+ );
+ $base_img->setscanline
+ (
+ x => 0,
+ y => 1,
+ pixels =>
+ [
+ map Imager::Color->new($_),
+ qw/FFFF00FF FF000000 00FF0080 00008040/
+ ]
+ );
+ my $base_fill = Imager::Fill->new
+ (
+ image => $base_img,
+ combine => "normal",
+ );
+ ok($base_fill, "make the base image fill");
+ my $fill50 = Imager::Fill->new(type => "opacity", opacity => 0.5, other => $base_fill)
+ or print "# ", Imager->errstr, "\n";
+ ok($fill50, "make 50% alpha translation fill");
+ my $out = Imager->new(xsize => 10, ysize => 10, channels => 4);
+ $out->box(fill => $fill50);
+ is_color4($out->getpixel(x => 0, y => 0),
+ 255, 0, 0, 16, "check alpha output");
+ is_color4($out->getpixel(x => 2, y => 1),
+ 0, 255, 0, 64, "check alpha output");
+ $out->box(filled => 1, color => "000000");
+ is_color4($out->getpixel(x => 0, y => 0),
+ 0, 0, 0, 255, "check after clear");
+ $out->box(fill => $fill50);
+ is_color4($out->getpixel(x => 4, y => 2),
+ 16, 0, 0, 255, "check drawn against background");
+ is_color4($out->getpixel(x => 6, y => 3),
+ 0, 64, 0, 255, "check drawn against background");
+ }
+ { # double/sample
+ use Imager::Color::Float;
+ my $base_img = Imager->new(xsize => 4, ysize => 2, channels => 4, bits => "double");
+ $base_img->setscanline
+ (
+ x => 0,
+ y => 0,
+ pixels =>
+ [
+ map Imager::Color::Float->new(@$_),
+ [ 1, 0, 0, 0.125 ],
+ [ 0, 1, 0, 0.5 ],
+ [ 0, 0, 0.5, 0.25 ],
+ [ 1, 1, 0, 1 ],
+ ],
+ );
+ $base_img->setscanline
+ (
+ x => 0,
+ y => 1,
+ pixels =>
+ [
+ map Imager::Color::Float->new(@$_),
+ [ 1, 1, 0, 1 ],
+ [ 1, 0, 0, 0 ],
+ [ 0, 1, 0, 0.5 ],
+ [ 0, 0, 0.5, 0.25 ],
+ ]
+ );
+ my $base_fill = Imager::Fill->new
+ (
+ image => $base_img,
+ combine => "normal",
+ );
+ ok($base_fill, "make the base image fill");
+ my $fill50 = Imager::Fill->new(type => "opacity", opacity => 0.5, other => $base_fill)
+ or print "# ", Imager->errstr, "\n";
+ ok($fill50, "make 50% alpha translation fill");
+ my $out = Imager->new(xsize => 10, ysize => 10, channels => 4, bits => "double");
+ $out->box(fill => $fill50);
+ is_fcolor4($out->getpixel(x => 0, y => 0, type => "float"),
+ 1, 0, 0, 0.0625, "check alpha output at 0,0");
+ is_fcolor4($out->getpixel(x => 2, y => 1, type => "float"),
+ 0, 1, 0, 0.25, "check alpha output at 2,1");
+ $out->box(filled => 1, color => "000000");
+ is_fcolor4($out->getpixel(x => 0, y => 0, type => "float"),
+ 0, 0, 0, 1, "check after clear");
+ $out->box(fill => $fill50);
+ is_fcolor4($out->getpixel(x => 4, y => 2, type => "float"),
+ 0.0625, 0, 0, 1, "check drawn against background at 4,2");
+ is_fcolor4($out->getpixel(x => 6, y => 3, type => "float"),
+ 0, 0.25, 0, 1, "check drawn against background at 6,3");
+ }
+ ok(!Imager::Fill->new(type => "opacity"),
+ "should fail to make an opacity fill with no other fill object");
+ is(Imager->errstr, "'other' parameter required to create opacity fill",
+ "check error message");
+ ok(!Imager::Fill->new(type => "opacity", other => "xx"),
+ "should fail to make an opacity fill with a bad other parameter");
+ is(Imager->errstr, "'other' parameter must be an Imager::Fill object to create an opacity fill",
+ "check error message");
+
+ # check auto conversion of hashes
+ ok(Imager::Fill->new(type => "opacity", other => { solid => "FF0000" }),
+ "check we auto-create fills")
+ or print "# ", Imager->errstr, "\n";
+}
+
sub color_close {
my ($c1, $c2) = @_;
Modified: branches/upstream/libimager-perl/current/t/t61filters.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libimager-perl/current/t/t61filters.t?rev=47313&op=diff
==============================================================================
--- branches/upstream/libimager-perl/current/t/t61filters.t (original)
+++ branches/upstream/libimager-perl/current/t/t61filters.t Mon Nov 16 18:13:07 2009
@@ -1,7 +1,7 @@
#!perl -w
use strict;
use Imager qw(:handy);
-use Test::More tests => 73;
+use Test::More tests => 79;
Imager::init_log("testout/t61filters.log", 1);
use Imager::Test qw(is_image_similar test_image is_image);
# meant for testing the filters themselves
@@ -17,8 +17,31 @@
'testout/t61_contrast.ppm');
# this one's kind of cool
-test($imbase, {type=>'conv', coef=>[ -0.5, 1, -0.5, ], },
- 'testout/t61_conv.ppm');
+test($imbase, {type=>'conv', coef=>[ 0.3, 1, 0.3, ], },
+ 'testout/t61_conv_blur.ppm');
+
+{
+ my $work8 = $imbase->copy;
+ ok(!$work8->filter(type => "conv", coef => "ABC"),
+ "coef not an array");
+}
+{
+ my $work8 = $imbase->copy;
+ ok(!$work8->filter(type => "conv", coef => [ -1, 2, -1 ]),
+ "should fail if sum of coef is 0");
+ is($work8->errstr, "sum of coefficients is zero", "check message");
+}
+
+{
+ my $work8 = $imbase->copy;
+ my $work16 = $imbase->to_rgb16;
+ my $coef = [ -0.2, 1, -0.2 ];
+ ok($work8->filter(type => "conv", coef => $coef),
+ "filter 8 bit image");
+ ok($work16->filter(type => "conv", , coef => $coef),
+ "filter 16 bit image");
+ is_image_similar($work8, $work16, 80000, "8 and 16 bit conv match");
+}
{
my $gauss = test($imbase, {type=>'gaussian', stddev=>5 },
@@ -292,6 +315,7 @@
or print "# ",$copy->errstr,"\n";
}
else {
+ diag($copy->errstr);
SKIP:
{
skip("couldn't filter", 1);
More information about the Pkg-perl-cvs-commits
mailing list