| 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 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 1 | ▶ | use vars qw($VERSION); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 1 | $VERSION = '0.02'; | |||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 1 | ▶ | use Imager (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 4 | ▶ | sub convert { | ||||||||||||||||||
|
Subroutine
convert: called CC=6 SCAR=18.2
Pod
undocumented
| |||||||||||||||||||||
| 16 | 4 | my($class, $image_base) = @_; | |||||||||||||||||||
| 17 | 4 | my($w, $h) = $image_base->get('-width', '-height'); | |||||||||||||||||||
| 18 | 4 | ▶ | my $has_transparency = $class->can('_has_transparency') && $class->_has_transparency($image_base); | ||||||||||||||||||
|
Condition66%2/3
$class->can('_has_transparency') && $class->_has_transparency($image_base)
MC/DC50%1/2
$class->can('_has_transparency') && $class->_has_transparency($image_base)
$class->can('_has_transparency')
$class->_has_transparency($image_base)
Truth table66%2/3
A && B
A= $class->can('_has_transparency')B= $class->_has_transparency($image_base)
| |||||||||||||||||||||
| 19 | 4 | my $imager = Imager->new(xsize => $w, ysize => $h, (channels => 4) x!! $has_transparency); | |||||||||||||||||||
| 20 | 4 | for my $x (0 .. $w-1) { | |||||||||||||||||||
| 21 | 272 | for my $y (0 .. $h-1) { | |||||||||||||||||||
| 22 | 3494 | my $color = $image_base->xy($x, $y); | |||||||||||||||||||
| 23 | 3494 | ▶ | if ($color =~ m{^(#..)..(..)..(..)..$}) { # convert #RRRRGGGGBBBB to #RRGGBB | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 24 | 0 | $color = "$1$2$3"; | |||||||||||||||||||
| 25 | } elsif ($color =~ m{^none$}i) { | ||||||||||||||||||||
| 26 | 72 | $color = '#00000000'; | |||||||||||||||||||
| 27 | } | ||||||||||||||||||||
| 28 | 3494 | $imager->setpixel(x => $x, y => $y, color => $color); | |||||||||||||||||||
| 29 | } | ||||||||||||||||||||
| 30 | } | ||||||||||||||||||||
| 31 | 4 | $imager; | |||||||||||||||||||
| 32 | } | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 1 | 1; | |||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | __END__ | ||||||||||||||||||||