Image.pm

filter: Statementstmt 25.7% 17 / 66 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 22 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 45.4% 5 / 11 Podpod 60.0% 3 / 5 totaltotal 17.3% 25 / 144 CC 24 SCAR 39.6
CC
24
Cov
14%
colour_to_pixel
110.0
new
56.0
xy
42.0
CRAP 52.5
« Pixmap.pm ↑ Summary Drawable.pm »
1 # Copyright 2010, 2011, 2012 Kevin Ryde
2  
3 # This file is part of Image-Base-Gtk2.
4 #
5 # Image-Base-Gtk2 is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the Free
7 # Software Foundation; either version 3, or (at your option) any later
8 # version.
9 #
10 # Image-Base-Gtk2 is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 # for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with Image-Base-Gtk2. If not, see <http://www.gnu.org/licenses/>.
17  
18  
19 package Image::Base::Gtk2::Gdk::Image;
20 1 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 1 our $VERSION = 11;
26 1 ▶use base 'Image::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 # uncomment this to run the ### lines
29 #use Smart::Comments;
30  
31  
32 0 ▶sub new {
Subroutine new: not called CC=7 SCAR=40.3
Pod documented
33 0 my ($class, %params) = @_;
34 ### Image-GdkImage new: \%params
35  
36 # $obj->new(...) means make a copy, with some extra settings
37 0 ▶ if (ref $class) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $class) 0 0 0
38 0 croak "Cannot clone a GdkImage yet";
39 }
40  
41 0 ▶ if (! exists $params{'-gdkimage'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $params{"-gdkimage"}) 0 0 0
42 ### create new GdkImage
43  
44 0 ▶ my $image_type = delete $params{'-image_type'} || 'fastest';
Condition0%0/2
delete $params{'-image_type'} || 'fastest'
l!l
00
MC/DC0%0/1
delete $params{'-image_type'} || 'fastest'
delete $params{'-image_type'}
Truth table0%0/2
A
A= delete $params{'-image_type'}
Aresult
11
00
45 my $visual = delete $params{'-visual'}
46 0 ▶ || ($params{'-colormap'} && $params{'-colormap'}->get_visual)
Condition0%0/9
delete $params{'-visual'} || $params{'-colormap'} && $params{'-colormap'}->get_visual || 'Gtk2::Gdk::Visual'->get_system
l!l&&r!l&&!r
000
delete $params{"-visual"} or $params{"-colormap"} and $params{"-colormap"}->get_visual
l!l&&r!l&&!r
000
$params{"-colormap"} and $params{"-colormap"}->get_visual
!ll&&!rl&&r
000
MC/DC0%0/4
delete $params{'-visual'} || $params{'-colormap'} && $params{'-colormap'}->get_visual || 'Gtk2::Gdk::Visual'->get_system
delete $params{"-visual"} $params{"-colormap"} $params{"-colormap"}->get_visual 'Gtk2::Gdk::Visual'->get_system
Truth table0%0/6
A or B and C || D
A= delete $params{"-visual"}B= $params{"-colormap"}C= $params{"-colormap"}->get_visualD= 'Gtk2::Gdk::Visual'->get_system
ABCDresult
1XXX1
011X1
00X11
01011
00X00
01000
47 || Gtk2::Gdk::Visual->get_system;
48 ### $image_type
49 ### $visual
50  
51 $params{'-gdkimage'} = Gtk2::Gdk::Image->new ($image_type,
52 $visual,
53 delete $params{'-width'},
54 0 delete $params{'-height'});
55 }
56  
57 0 my $self = bless {}, $class;
58 0 $self->set (%params);
59 ### $self
60 0 return $self;
61 }
62  
63 1 my %attr_to_get_method = (-colormap => 'get_colormap',
64 -visual => 'get_visual',
65 -width => 'get_width',
66 -height => 'get_height',
67 -depth => 'get_depth',
68  
69 # not documented yet, maybe a more specific name ...
70 -image_type => 'get_image_type',
71 );
72 0 ▶sub _get {
Subroutine _get: not called CC=2 SCAR=17.9
73 0 my ($self, $key) = @_;
74  
75 0 ▶ if (my $method = $attr_to_get_method{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $method = $attr_to_get_method{$key}) 0 0 0
76 0 return $self->{'-gdkimage'}->$method;
77 }
78 0 return $self->SUPER::_get($key);
79 }
80  
81 0 ▶sub set {
Subroutine set: not called CC=2 SCAR=17.9
Pod documented
82 0 my ($self, %params) = @_;
83 ### Image-GdkImage set(): \%params
84  
85 0 %$self = (%$self, %params);
86  
87 0 ▶ if (defined (my $colormap = delete $self->{'-colormap'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $colormap = delete $self->{"-colormap"})) 0 0 0
88 0 $self->{'-gdkimage'}->set_colormap ($colormap);
89 }
90 ### set leaves: $self
91 }
92  
93 #------------------------------------------------------------------------------
94 # drawing
95  
96 0 ▶sub xy {
Subroutine xy: not called CC=6 SCAR=37.4
Pod documented
97 0 my ($self, $x, $y, $colour) = @_;
98  
99 0 my $gdkimage = $self->{'-gdkimage'};
100 0 ▶ unless ($x >= 0
Branch: 1 branch
BranchTrueFalseTotal
unless ($x >= 0 and $y >= 0 and $x < $gdkimage->get_width and $y < $gdkimage->get_height) 0 0 0
Condition0%0/9
$x >= 0 and $y >= 0 and $x < $gdkimage->get_width and $y < $gdkimage->get_height
!ll&&!rl&&r
000
$x >= 0 and $y >= 0 and $x < $gdkimage->get_width
!ll&&!rl&&r
000
$x >= 0 and $y >= 0
!ll&&!rl&&r
000
MC/DC0%0/4
$x >= 0 and $y >= 0 and $x < $gdkimage->get_width and $y < $gdkimage->get_height
$x >= 0 $y >= 0 $x < $gdkimage->get_width $y < $gdkimage->get_height
Truth table0%0/5
A and B and C and D
A= $x >= 0B= $y >= 0C= $x < $gdkimage->get_widthD= $y < $gdkimage->get_height
ABCDresult
0XXX0
10XX0
110X0
11100
11111
101 && $y >= 0
102 && $x < $gdkimage->get_width
103 && $y < $gdkimage->get_height) {
104 ### outside 0,0,width,height ...
105 0 return undef; # fetch or store
106 }
107  
108 0 ▶ if (@_ >= 4) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ >= 4) { } 0 0 0
109 ### Image-GdkImage xy: "$x, $y, $colour"
110 0 $gdkimage->put_pixel ($x,$y, $self->colour_to_pixel($colour));
111 } else {
112 0 return $self->pixel_to_colour($gdkimage->get_pixel ($x,$y))
113 }
114 }
115  
116 0 ▶sub colour_to_pixel {
Subroutine colour_to_pixel: not called CC=10 SCAR=47.0
Pod undocumented
117 0 my ($self, $colour) = @_;
118 ### colour_to_pixel: $colour
119 0 ▶ if (defined (my $pixel = $self->{'-colour_to_pixel'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $pixel = $self->{"-colour_to_pixel"})) 0 0 0
120 0 return $pixel;
121 }
122 0 ▶ if ($colour =~ /^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($colour =~ /^\d+$/) 0 0 0
123 0 return $colour;
124 }
125 0 ▶ if ($colour eq 'set') {
Branch: 1 branch
BranchTrueFalseTotal
if ($colour eq "set") 0 0 0
126 0 return 1;
127 }
128 0 ▶ if ($colour eq 'clear') {
Branch: 1 branch
BranchTrueFalseTotal
if ($colour eq "clear") 0 0 0
129 0 return 0;
130 }
131  
132 0 my $gdkimage = $self->{'-gdkimage'};
133 0 ▶ if (my $colormap = $gdkimage->get_colormap) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $colormap = $gdkimage->get_colormap) 0 0 0
134 # think parse and rgb_find are client-side operations, no need to cache
135 # the results
136 #
137 0 ▶ my $colorobj = Gtk2::Gdk::Color->parse ($colour)
Condition0%0/2
'Gtk2::Gdk::Color'->parse($colour) || croak("Cannot parse colour: $colour")
l!l
00
MC/DC0%0/1
'Gtk2::Gdk::Color'->parse($colour) || croak("Cannot parse colour: $colour")
'Gtk2::Gdk::Color'->parse($colour)
Truth table0%0/2
A
A= 'Gtk2::Gdk::Color'->parse($colour)
Aresult
11
00
138 || croak "Cannot parse colour: $colour";
139 0 $colormap->rgb_find_color ($colorobj);
140 ### rgb_find_color: $colorobj->to_string
141 ### pixel: $colorobj->pixel
142 0 return $colorobj->pixel;
143 }
144 0 ▶ if ($gdkimage->get_depth == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gdkimage->get_depth == 1) 0 0 0
145 0 ▶ if ($colour =~ /^#(000)+$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($colour =~ /^#(000)+$/) { } 0 0 0
elsif ($colour =~ /^#(FFF)+$/i) { } 0 0 0
146 0 return 0;
147 } elsif ($colour =~ /^#(FFF)+$/i) {
148 0 return 1;
149 }
150 }
151 0 croak "No colormap to interpret colour: $colour";
152 }
153  
154 0 ▶sub pixel_to_colour {
Subroutine pixel_to_colour: not called CC=2 SCAR=17.9
Pod undocumented
155 0 my ($self, $pixel) = @_;
156 ### pixel_to_colour: $pixel
157 0 ▶ if (my $colormap = $self->{'-gdkimage'}->get_colormap) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $colormap = $self->{'-gdkimage'}->get_colormap) { } 0 0 0
158 0 my $colorobj = $colormap->query_color($pixel);
159 ### in colormap: $colorobj->to_string
160 ### pixel: $colorobj->pixel
161 0 return sprintf '#%04X%04X%04X',
162 $colorobj->red, $colorobj->green, $colorobj->blue;
163 } else {
164 0 return $pixel;
165 }
166 }
167  
168 1 1;
169 __END__
« Pixmap.pm ↑ Summary Drawable.pm »