File Coverage

blib/lib/Imager/Image/Base.pm
Criterion Covered Total %
statement 20 21 95.2
branch 3 4 75.0
condition 2 3 66.6
subroutine 4 4 100.0
pod 0 1 0.0
total 29 33 87.8


line stmt bran cond sub pod time code
1             # -*- perl -*-
2              
3             # Copyright (C) 2015 Slaven Rezic. All rights reserved.
4             # This package is free software; you can redistribute it and/or
5             # modify it under the same terms as Perl itself.
6              
7             package Imager::Image::Base;
8              
9 1     1   15610 use strict;
  1         1  
  1         34  
10 1     1   4 use vars qw($VERSION);
  1         1  
  1         42  
11             $VERSION = '0.02';
12              
13 1     1   743 use Imager ();
  1         30800  
  1         195  
14              
15             sub convert {
16 4     4 0 1601 my($class, $image_base) = @_;
17 4         9 my($w, $h) = $image_base->get('-width', '-height');
18 4   66     72 my $has_transparency = $class->can('_has_transparency') && $class->_has_transparency($image_base);
19 4         25 my $imager = Imager->new(xsize => $w, ysize => $h, (channels => 4) x!! $has_transparency);
20 4         188 for my $x (0 .. $w-1) {
21 272         13575 for my $y (0 .. $h-1) {
22 3494         164835 my $color = $image_base->xy($x, $y);
23 3494 50       26008 if ($color =~ m{^(#..)..(..)..(..)..$}) { # convert #RRRRGGGGBBBB to #RRGGBB
    100          
24 0         0 $color = "$1$2$3";
25             } elsif ($color =~ m{^none$}i) {
26 72         46 $color = '#00000000';
27             }
28 3494         5012 $imager->setpixel(x => $x, y => $y, color => $color);
29             }
30             }
31 4         235 $imager;
32             }
33              
34             1;
35              
36             __END__