Skip to content

Commit

Permalink
fix rendering on alpha channel images for the FreeType 1.x driver.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony Cook committed May 5, 2007
1 parent 01524c4 commit fa16b6c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
3 changes: 3 additions & 0 deletions Changes
Expand Up @@ -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
===========

Expand Down
21 changes: 14 additions & 7 deletions font.c
@@ -1,4 +1,5 @@
#include "imager.h"
#include "imrender.h"

#include <sys/types.h>
#include <sys/stat.h>
Expand Down Expand Up @@ -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;
Expand Down
28 changes: 23 additions & 5 deletions t/t35ttfont.t
@@ -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";

Expand All @@ -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();
Expand Down Expand Up @@ -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");
}

Expand All @@ -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");
}

0 comments on commit fa16b6c

Please sign in to comment.