]> git.imager.perl.org - imager.git/commitdiff
fix rendering on alpha channel images for the FreeType 1.x driver.
authorTony Cook <tony@develop=help.com>
Sat, 5 May 2007 00:30:34 +0000 (00:30 +0000)
committerTony Cook <tony@develop=help.com>
Sat, 5 May 2007 00:30:34 +0000 (00:30 +0000)
Changes
font.c
t/t35ttfont.t

diff --git a/Changes b/Changes
index 133ebfa60c4ac71aada657bec56987cc0093c2b2..c36aeabdc5f658692c6a1f4979f55e0dfc94e44d 100644 (file)
--- a/Changes
+++ b/Changes
@@ -23,6 +23,9 @@ Bug fixes:
    regenerate Inline code when a new release of Imager is installed.
    http://rt.cpan.org/Ticket/Display.html?id=26278
 
+ - fix rendering on alpha channel images for the FreeType 1.x driver.
+   http://rt.cpan.org/Ticket/Display.html?id=11972
+
 Imager 0.57 - 30 Apr 2007
 ===========
 
diff --git a/font.c b/font.c
index 87c70bc550abba4d9f14d283bc6e83dd7854c5da..7a2b864d4faacc651d87922c419de74d0cd9ecd1 100644 (file)
--- a/font.c
+++ b/font.c
@@ -1,4 +1,5 @@
 #include "imager.h"
+#include "imrender.h"
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -1522,17 +1523,23 @@ i_tt_dump_raster_map2( i_img* im, TT_Raster_Map* bit, int xb, int yb, const i_co
 
   if ( smooth ) {
 
+    i_render r;
+    i_render_init(&r, im, bit->cols);
     for(y=0;y<bit->rows;y++) {
+#if 0
       for(x=0;x<bit->width;x++) {
-       c = (unsigned char)bmap[y*(bit->cols)+x];
-       i=255-c;
-       i_gpix(im,x+xb,y+yb,&val);
-       for(ch=0;ch<im->channels;ch++) 
-         val.channel[ch] = (c*cl->channel[ch]+i*val.channel[ch])/255;
-       i_ppix(im,x+xb,y+yb,&val);
+       c = (unsigned char)bmap[y*(bit->cols)+x];
+       i=255-c;
+       i_gpix(im,x+xb,y+yb,&val);
+       for(ch=0;ch<im->channels;ch++) 
+         val.channel[ch] = (c*cl->channel[ch]+i*val.channel[ch])/255;
+       i_ppix(im,x+xb,y+yb,&val);
       }
+#else
+      i_render_color(&r, xb, yb+y, bit->cols, bmap + y*bit->cols, cl);
+#endif
     }
-
+    i_render_done(&r);
   } else {
     for(y=0;y<bit->rows;y++) {
       unsigned mask = 0x80;
index 666c6bfa1db336fae46b29ffa94574546dd00489..f628952a486d1597c865f3eb17e5cdbf22e2560a 100644 (file)
@@ -1,18 +1,18 @@
 #!perl -w
 use strict;
-use Test::More tests => 87;
+use Test::More tests => 91;
 
 $|=1;
 
 BEGIN { use_ok(Imager => ':all') }
 require "t/testtools.pl";
-use Imager::Test qw(diff_text_with_nul);
+use Imager::Test qw(diff_text_with_nul is_color3);
 
 init_log("testout/t35ttfont.log",2);
 
 SKIP:
 {
-  skip("freetype 1.x unavailable or disabled", 86
+  skip("freetype 1.x unavailable or disabled", 90
     unless i_has_format("tt");
   print "# has tt\n";
   
@@ -21,7 +21,7 @@ SKIP:
 
   if (!ok(-f $fontname, "check test font file exists")) {
     print "# cannot find fontfile for truetype test $fontname\n";
-    skip('Cannot load test font', 85);
+    skip('Cannot load test font', 89);
   }
 
   i_init_fonts();
@@ -260,7 +260,7 @@ SKIP:
   { # introduced in 0.46 - outputting just space crashes
     my $im = Imager->new(xsize=>100, ysize=>100);
     my $font = Imager::Font->new(file=>'fontfiles/ImUgly.ttf', size=>14);
-    ok($im->string(font=>$font, x=> 5, y => 50, string=>' '),
+    ok($im->string(font=>$font, x=> 5, 'y' => 50, string=>' '),
       "outputting just a space was crashing");
   }
 
@@ -282,5 +282,23 @@ SKIP:
                       font => $font, channel => 1, utf8 => 1);
   }
 
+  { # RT 11972
+    # when rendering to a transparent image the coverage should be
+    # expressed in terms of the alpha channel rather than the color
+    my $font = Imager::Font->new(file=>'fontfiles/ImUgly.ttf', type=>'tt');
+    my $im = Imager->new(xsize => 40, ysize => 20, channels => 4);
+    ok($im->string(string => "AB", size => 20, aa => 1, color => '#F00',
+                  x => 0, y => 15, font => $font),
+       "draw to transparent image");
+    #$im->write(file => "foo.png");
+    my $im_noalpha = $im->convert(preset => 'noalpha');
+    my $im_pal = $im->to_paletted(make_colors => 'mediancut');
+    my @colors = $im_pal->getcolors;
+    is(@colors, 2, "should be only 2 colors");
+    @colors = sort { ($a->rgba)[0] <=> ($b->rgba)[0] } @colors;
+    is_color3($colors[0], 0, 0, 0, "check we got black");
+    is_color3($colors[1], 255, 0, 0, "and red");
+  }
+
   ok(1, "end of code");
 }