]> git.imager.perl.org - imager.git/commitdiff
- added log() and exp() functions to transform2()
authorTony Cook <tony@develop=help.com>
Thu, 5 Feb 2004 04:32:16 +0000 (04:32 +0000)
committerTony Cook <tony@develop=help.com>
Thu, 5 Feb 2004 04:32:16 +0000 (04:32 +0000)
- change the getpN() functions in transform2() to set a
  reasonable alpha if the input image has no alpha
- document the constants that transform2() defines

Changes
lib/Imager/Regops.pm
lib/Imager/Transformations.pod
regmach.c
regmach.h
t/t58trans2.t

diff --git a/Changes b/Changes
index 630f1f1fdddd0a3e342ca3de2174c616bd03ac0a..39056ee41251991ca6fb0c81536421b52c702c1b 100644 (file)
--- 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:
index 644b8b5e49815fa3c58e108acb8f1bee4bbcbcec..ad169f82547a88e9cd778e4a57f5347e185942f2 100644 (file)
@@ -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
 
index 46ccaeb315387f9198da21265ab1b16d9619e9ab..a7099bacb1899c01c640b9745b5f96d0ec8bf0ab 100644 (file)
@@ -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 );
index cea9a791fdaebf683e472d839c45c19c0410e9f1..1659a530ef0bbaac0eacee5b4ac84e563d25c592 100644 (file)
--- a/regmach.c
+++ b/regmach.c
@@ -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;
index 79b8fda2713d08538c2c30c1617e6f90644365ff..448ef7a93b37b2de9edcef7f6029a0251ef85c1a 100644 (file)
--- 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
 };
 
index 163570d221fccdad1f24b10dc2880f19e9e24147..5b29e6a02c37273875f43997eb79894f118a5ea9 100644 (file)
@@ -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