Permalink
Browse files

- 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
  • Loading branch information...
1 parent 3a6bb91 commit aed9d070f856d2355195f361799d70852b163cd8 Tony Cook committed Feb 5, 2004
Showing with 67 additions and 5 deletions.
  1. +6 −0 Changes
  2. +20 −4 lib/Imager/Regops.pm
  3. +4 −0 lib/Imager/Transformations.pod
  4. +27 −0 regmach.c
  5. +2 −0 regmach.h
  6. +8 −1 t/t58trans2.t
View
@@ -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:
View
@@ -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
@@ -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 );
View
@@ -1,4 +1,5 @@
#include "regmach.h"
+#include <float.h>
/*#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;
View
@@ -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
};
View
@@ -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

0 comments on commit aed9d07

Please sign in to comment.