From: Tony Cook Date: Thu, 5 Feb 2004 04:32:16 +0000 (+0000) Subject: - added log() and exp() functions to transform2() X-Git-Tag: Imager-0.48^2~330 X-Git-Url: http://git.imager.perl.org/imager.git/commitdiff_plain/aed9d070f856d2355195f361799d70852b163cd8 - added log() and exp() functions to transform2() - change the getpN() functions in transform2() to set a reasonable alpha if the input image has no alpha - document the constants that transform2() defines --- diff --git a/Changes b/Changes index 630f1f1f..39056ee4 100644 --- a/Changes +++ b/Changes @@ -732,6 +732,12 @@ Revision history for Perl extension Imager. - removed all references to the www.eecs.umich.edu page and changed them to imager.perl.org ones. +0.43pre1 + - added log() and exp() functions to transform2() + - change the getpN() functions in transform2() to set a + reasonable alpha if the input image has no alpha + - document the constants that transform2() defines + ================================================================= For latest versions check the Imager-devel pages: diff --git a/lib/Imager/Regops.pm b/lib/Imager/Regops.pm index 644b8b5e..ad169f82 100644 --- a/lib/Imager/Regops.pm +++ b/lib/Imager/Regops.pm @@ -55,9 +55,11 @@ use constant RBC_PRINT => 45; use constant RBC_RGBA => 46; use constant RBC_HSVA => 47; use constant RBC_ALPHA => 48; -use constant RBC_OP_COUNT => 49; +use constant RBC_LOG => 49; +use constant RBC_EXP => 50; +use constant RBC_OP_COUNT => 51; -@EXPORT = qw(RBC_ADD RBC_SUBTRACT RBC_MULT RBC_DIV RBC_MOD RBC_POW RBC_UMINUS RBC_MULTP RBC_ADDP RBC_SUBTRACTP RBC_SIN RBC_COS RBC_ATAN2 RBC_SQRT RBC_DISTANCE RBC_GETP1 RBC_GETP2 RBC_GETP3 RBC_VALUE RBC_HUE RBC_SAT RBC_HSV RBC_RED RBC_GREEN RBC_BLUE RBC_RGB RBC_INT RBC_IF RBC_IFP RBC_LE RBC_LT RBC_GE RBC_GT RBC_EQ RBC_NE RBC_AND RBC_OR RBC_NOT RBC_ABS RBC_RET RBC_JUMP RBC_JUMPZ RBC_JUMPNZ RBC_SET RBC_SETP RBC_PRINT RBC_RGBA RBC_HSVA RBC_ALPHA RBC_OP_COUNT); +@EXPORT = qw(RBC_ADD RBC_SUBTRACT RBC_MULT RBC_DIV RBC_MOD RBC_POW RBC_UMINUS RBC_MULTP RBC_ADDP RBC_SUBTRACTP RBC_SIN RBC_COS RBC_ATAN2 RBC_SQRT RBC_DISTANCE RBC_GETP1 RBC_GETP2 RBC_GETP3 RBC_VALUE RBC_HUE RBC_SAT RBC_HSV RBC_RED RBC_GREEN RBC_BLUE RBC_RGB RBC_INT RBC_IF RBC_IFP RBC_LE RBC_LT RBC_GE RBC_GT RBC_EQ RBC_NE RBC_AND RBC_OR RBC_NOT RBC_ABS RBC_RET RBC_JUMP RBC_JUMPZ RBC_JUMPNZ RBC_SET RBC_SETP RBC_PRINT RBC_RGBA RBC_HSVA RBC_ALPHA RBC_LOG RBC_EXP RBC_OP_COUNT); %Attr = ( 'setp' => { @@ -319,6 +321,13 @@ use constant RBC_OP_COUNT => 49; 'func' => 1, 'types' => 'p' }, + 'log' => { + 'result' => 'r', + 'parms' => 1, + 'opcode' => 49, + 'func' => 1, + 'types' => 'r' + }, 'hsva' => { 'result' => 'p', 'parms' => 4, @@ -357,7 +366,7 @@ use constant RBC_OP_COUNT => 49; 'op_count' => { 'result' => undef, 'parms' => 0, - 'opcode' => 49, + 'opcode' => 51, 'func' => 0, 'types' => '' }, @@ -382,6 +391,13 @@ use constant RBC_OP_COUNT => 49; 'func' => 0, 'types' => 'rr' }, + 'exp' => { + 'result' => 'r', + 'parms' => 1, + 'opcode' => 50, + 'func' => 1, + 'types' => 'r' + }, 'subtract' => { 'result' => 'r', 'parms' => 2, @@ -444,7 +460,7 @@ Tony Cook, tony@develop-help.com =head1 SEE ALSO -perl(1), Imager(3), http://www.eecs.umich.edu/~addi/perl/Imager/ +perl(1), Imager(3), http://imager.perl.org/~addi/perl/Imager/ =cut diff --git a/lib/Imager/Transformations.pod b/lib/Imager/Transformations.pod index 46ccaeb3..a7099bac 100644 --- a/lib/Imager/Transformations.pod +++ b/lib/Imager/Transformations.pod @@ -40,6 +40,10 @@ Imager::Transformations - Simple transformations of one image into another. [ 1, 0, 0 ], [ 0, 0, 1 ] ]); + # image composition + $img->compose(img=>$source, mask=>$mask, left=>100, top=>50) + or die $img->errstr; + # limit the range of red channel from 0..255 to 0..127 @map = map { int( $_/2 } 0..255; $img->map( red=>\@map ); diff --git a/regmach.c b/regmach.c index cea9a791..1659a530 100644 --- a/regmach.c +++ b/regmach.c @@ -1,4 +1,5 @@ #include "regmach.h" +#include /*#define DEBUG*/ #ifdef DEBUG @@ -7,6 +8,9 @@ #define DBG(x) #endif +static float MAX_EXP_ARG; /* = log(DBL_MAX); */ + + /* these functions currently assume RGB images - there seems to be some support for other color spaces, but I can't tell how you find what space an image is using. @@ -173,6 +177,7 @@ i_color i_rm_run(struct rm_op codes[], size_t code_count, double dx, dy; struct rm_op *codes_base = codes; size_t count_base = code_count; + DBG(("rm_run(%p, %d)\n", codes, code_count)); while (code_count) { DBG((" rm_code %d\n", codes->code)); @@ -250,14 +255,17 @@ i_color i_rm_run(struct rm_op codes[], size_t code_count, case rbc_getp1: i_gpix(images[0], na, nb, c_regs+codes->rout); + if (images[0]->channels < 4) cout.rgba.a = 255; break; case rbc_getp2: i_gpix(images[1], na, nb, c_regs+codes->rout); + if (images[1]->channels < 4) cout.rgba.a = 255; break; case rbc_getp3: i_gpix(images[2], na, nb, c_regs+codes->rout); + if (images[2]->channels < 4) cout.rgba.a = 255; break; case rbc_value: @@ -392,6 +400,25 @@ i_color i_rm_run(struct rm_op codes[], size_t code_count, cout = ca; break; + case rbc_log: + if (na > 0) { + nout = log(na); + } + else { + nout = DBL_MAX; + } + break; + + case rbc_exp: + if (!MAX_EXP_ARG) MAX_EXP_ARG = log(DBL_MAX); + if (na <= MAX_EXP_ARG) { + nout = exp(na); + } + else { + nout = DBL_MAX; + } + break; + case rbc_print: printf("r%d is %g\n", codes->ra, na); break; diff --git a/regmach.h b/regmach.h index 79b8fda2..448ef7a9 100644 --- a/regmach.h +++ b/regmach.h @@ -57,6 +57,8 @@ enum rm_byte_codes { rbc_rgba, /* rgba(ra, rb, rc, rd) -> p */ rbc_hsva, /* hsva(ra, rb, rc, rd) -> p */ rbc_alpha, /* alpha(pa) -> r */ + rbc_log, /* log(ra) -> r */ + rbc_exp, /* exp(ra) -> r */ rbc_op_count }; diff --git a/t/t58trans2.t b/t/t58trans2.t index 163570d2..5b29e6a0 100644 --- a/t/t58trans2.t +++ b/t/t58trans2.t @@ -1,5 +1,5 @@ #!perl -w -BEGIN { $| = 1; print "1..15\n"; } +BEGIN { $| = 1; print "1..16\n"; } END {print "not ok 1\n" unless $loaded;} use Imager; @@ -74,6 +74,13 @@ is(($c->rgba)[3], 0, "zero alpha"); $c = $im8->getpixel(x=>49, 'y'=>49); is(($c->rgba)[3], 255, "max alpha"); +$opts = { rpnexpr => 'x 1 + log 50 * y 1 + log 50 * getp1' }; +my $im9 = Imager::transform2($opts, $im1); +ok($im9, "log function"); +if ($im9) { + $im9->write(type=>'pnm', file=>'testout/t56-9.ppm'); +} + use Imager::Transform; # some simple tests