| Filename | /home/ocbnet/domain/ocbnet.ch/vhost/webmerge/htdocs/webmerge/scripts/modules/OCBNET/Spritesets/Canvas/Repeater.pm |
| Statements | Executed 92610 statements in 3.85s |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 12 | 1 | 1 | 1.67s | 6.66s | OCBNET::Spritesets::Canvas::Repeater::repeater |
| 1 | 1 | 1 | 86µs | 185µs | OCBNET::Spritesets::Canvas::Repeater::BEGIN@10 |
| 1 | 1 | 1 | 69µs | 69µs | OCBNET::Spritesets::Canvas::Repeater::BEGIN@19.4 |
| 1 | 1 | 1 | 54µs | 86µs | OCBNET::Spritesets::Canvas::Repeater::BEGIN@11 |
| 1 | 1 | 1 | 40µs | 40µs | OCBNET::Spritesets::Canvas::Repeater::BEGIN@19 |
| 1 | 1 | 1 | 26µs | 26µs | OCBNET::Spritesets::Canvas::Repeater::BEGIN@22 |
| 1 | 1 | 1 | 21µs | 21µs | OCBNET::Spritesets::Canvas::Repeater::BEGIN@16 |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | ################################################################################################### | ||||
| 2 | # Copyright 2013 by Marcel Greter | ||||
| 3 | # This file is part of Webmerge (GPL3) | ||||
| 4 | #################################################################################################### | ||||
| 5 | # static helper functions for canvas | ||||
| 6 | #################################################################################################### | ||||
| 7 | package OCBNET::Spritesets::Canvas::Repeater; | ||||
| 8 | #################################################################################################### | ||||
| 9 | |||||
| 10 | 2 | 174µs | 2 | 283µs | # spent 185µs (86+98) within OCBNET::Spritesets::Canvas::Repeater::BEGIN@10 which was called:
# once (86µs+98µs) by OCBNET::Spritesets::Canvas::BEGIN@20 at line 10 # spent 185µs making 1 call to OCBNET::Spritesets::Canvas::Repeater::BEGIN@10
# spent 98µs making 1 call to strict::import |
| 11 | 2 | 189µs | 2 | 118µs | # spent 86µs (54+32) within OCBNET::Spritesets::Canvas::Repeater::BEGIN@11 which was called:
# once (54µs+32µs) by OCBNET::Spritesets::Canvas::BEGIN@20 at line 11 # spent 86µs making 1 call to OCBNET::Spritesets::Canvas::Repeater::BEGIN@11
# spent 32µs making 1 call to warnings::import |
| 12 | |||||
| 13 | ################################################################################################### | ||||
| 14 | |||||
| 15 | # define our version string | ||||
| 16 | 1 | 156µs | 1 | 21µs | # spent 21µs within OCBNET::Spritesets::Canvas::Repeater::BEGIN@16 which was called:
# once (21µs+0s) by OCBNET::Spritesets::Canvas::BEGIN@20 at line 16 # spent 21µs making 1 call to OCBNET::Spritesets::Canvas::Repeater::BEGIN@16 |
| 17 | |||||
| 18 | # load exporter and inherit from it | ||||
| 19 | 3 | 393µs | 2 | 109µs | # spent 40µs within OCBNET::Spritesets::Canvas::Repeater::BEGIN@19 which was called:
# once (40µs+0s) by OCBNET::Spritesets::Canvas::BEGIN@20 at line 19
# spent 69µs within OCBNET::Spritesets::Canvas::Repeater::BEGIN@19.4 which was called:
# once (69µs+0s) by OCBNET::Spritesets::Canvas::BEGIN@20 at line 19 # spent 69µs making 1 call to OCBNET::Spritesets::Canvas::Repeater::BEGIN@19.4
# spent 40µs making 1 call to OCBNET::Spritesets::Canvas::Repeater::BEGIN@19 |
| 20 | |||||
| 21 | # define our functions to be exported | ||||
| 22 | 1 | 3.52ms | 1 | 26µs | # spent 26µs within OCBNET::Spritesets::Canvas::Repeater::BEGIN@22 which was called:
# once (26µs+0s) by OCBNET::Spritesets::Canvas::BEGIN@20 at line 22 # spent 26µs making 1 call to OCBNET::Spritesets::Canvas::Repeater::BEGIN@22 |
| 23 | |||||
| 24 | #################################################################################################### | ||||
| 25 | |||||
| 26 | # draw repeating sprites | ||||
| 27 | # ****************************************************************************** | ||||
| 28 | sub repeater | ||||
| 29 | # spent 6.66s (1.67+4.99) within OCBNET::Spritesets::Canvas::Repeater::repeater which was called 12 times, avg 555ms/call:
# 12 times (1.67s+4.99s) by OCBNET::Spritesets::Canvas::draw at line 214 of webmerge/scripts/modules/OCBNET/Spritesets/Canvas.pm, avg 555ms/call | ||||
| 30 | |||||
| 31 | # get our object | ||||
| 32 | 12 | 61µs | my ($self) = shift; | ||
| 33 | |||||
| 34 | # process all possible areas | ||||
| 35 | 12 | 311µs | 12 | 622µs | foreach my $area ($self->areas) # spent 622µs making 12 calls to OCBNET::Spritesets::Canvas::areas, avg 52µs/call |
| 36 | { | ||||
| 37 | |||||
| 38 | # ignore area if it's empty | ||||
| 39 | 156 | 2.29ms | 156 | 2.58ms | next if $area->empty; # spent 2.58ms making 156 calls to OCBNET::Spritesets::Container::empty, avg 17µs/call |
| 40 | |||||
| 41 | # get our own dimensions | ||||
| 42 | 108 | 1.56ms | 108 | 1.34ms | my $width = $self->width; # spent 1.34ms making 108 calls to OCBNET::Spritesets::Block::width, avg 12µs/call |
| 43 | 108 | 1.34ms | 108 | 1.24ms | my $height = $self->height; # spent 1.24ms making 108 calls to OCBNET::Spritesets::Block::height, avg 12µs/call |
| 44 | |||||
| 45 | ########################################################## | ||||
| 46 | # draw repeating patterns on the canvas | ||||
| 47 | ########################################################## | ||||
| 48 | |||||
| 49 | 108 | 9.41ms | 268 | 3.47ms | if ( # spent 3.47ms making 268 calls to UNIVERSAL::isa, avg 13µs/call |
| 50 | |||||
| 51 | $area->isa('OCBNET::Spritesets::Fit') || | ||||
| 52 | $area->isa('OCBNET::Spritesets::Edge') || | ||||
| 53 | $area->isa('OCBNET::Spritesets::Stack') | ||||
| 54 | ) | ||||
| 55 | { | ||||
| 56 | |||||
| 57 | # paint the repeatings | ||||
| 58 | # process all sprites on edge | ||||
| 59 | 76 | 1.35ms | 76 | 3.08ms | foreach my $sprite ($area->children) # spent 3.08ms making 76 calls to OCBNET::Spritesets::Container::children, avg 41µs/call |
| 60 | { | ||||
| 61 | |||||
| 62 | # get the sprite dimensions | ||||
| 63 | 4712 | 55.8ms | 4712 | 54.6ms | my $sprite_width = $sprite->width; # spent 54.6ms making 4712 calls to OCBNET::Spritesets::Block::width, avg 12µs/call |
| 64 | 4712 | 50.6ms | 4712 | 49.0ms | my $sprite_height = $sprite->height; # spent 49.0ms making 4712 calls to OCBNET::Spritesets::Block::height, avg 10µs/call |
| 65 | |||||
| 66 | # get the offset on the canvas | ||||
| 67 | 4712 | 53.6ms | 4712 | 1.98s | my $offset = $sprite->offset(); # spent 1.98s making 4712 calls to OCBNET::Spritesets::Sprite::offset, avg 420µs/call |
| 68 | |||||
| 69 | # get offset position of inner sprite image | ||||
| 70 | 4712 | 66.0ms | 4712 | 51.2ms | my $left = $offset->{'x'} + $sprite->paddingLeft; # spent 51.2ms making 4712 calls to OCBNET::Spritesets::Block::paddingLeft, avg 11µs/call |
| 71 | 4712 | 59.7ms | 4712 | 47.4ms | my $top = $offset->{'y'} + $sprite->paddingTop; # spent 47.4ms making 4712 calls to OCBNET::Spritesets::Block::paddingTop, avg 10µs/call |
| 72 | |||||
| 73 | # no sprite must repeat in both directions | ||||
| 74 | # XXX - maybe move this check to a better place | ||||
| 75 | 4712 | 49.6ms | 4944 | 53.3ms | if ($sprite->isRepeatX && $sprite->isRepeatY) # spent 50.5ms making 4712 calls to OCBNET::Spritesets::Sprite::isRepeatX, avg 11µs/call
# spent 2.89ms making 232 calls to OCBNET::Spritesets::Sprite::isRepeatY, avg 12µs/call |
| 76 | { die "fatal error: cannot repeat in both directions"; } | ||||
| 77 | |||||
| 78 | # is repeating on x axis | ||||
| 79 | 4712 | 121ms | 9192 | 91.8ms | if ($sprite->isRepeatX) # spent 46.1ms making 4480 calls to OCBNET::Spritesets::Sprite::isRepeatY, avg 10µs/call
# spent 45.7ms making 4712 calls to OCBNET::Spritesets::Sprite::isRepeatX, avg 10µs/call |
| 80 | { | ||||
| 81 | |||||
| 82 | # declare boundary vars | ||||
| 83 | 232 | 576µs | my ($lower_x, $upper_x); | ||
| 84 | |||||
| 85 | # check if sprite is fixed | ||||
| 86 | 232 | 3.61ms | 232 | 3.34ms | if ($sprite->isFixedX) # spent 3.34ms making 232 calls to OCBNET::Spritesets::Sprite::isFixedX, avg 14µs/call |
| 87 | { | ||||
| 88 | # get the lower boundary | ||||
| 89 | 168 | 604µs | $lower_x = $offset->{'x'}; | ||
| 90 | # sum up outer width and lower boundary | ||||
| 91 | 168 | 2.40ms | 168 | 16.1ms | $upper_x = $lower_x + $sprite->outerWidth; # spent 16.1ms making 168 calls to OCBNET::Spritesets::Block::outerWidth, avg 96µs/call |
| 92 | } | ||||
| 93 | # sprite has flexible width | ||||
| 94 | else | ||||
| 95 | { | ||||
| 96 | # go behind the left edge | ||||
| 97 | 64 | 175µs | $lower_x = - $sprite_width; | ||
| 98 | # and draw over the right edge | ||||
| 99 | 64 | 156µs | $upper_x = $width + $sprite_width; | ||
| 100 | } | ||||
| 101 | # EO if isFixedX | ||||
| 102 | |||||
| 103 | # draw the repeating patterns on the left side of the original drawn sprite | ||||
| 104 | 232 | 25.0ms | 336 | 6.91ms | for (my $i = $left - $sprite_width; $i > $lower_x - $sprite_width; $i -= $sprite_width) # spent 6.91ms making 336 calls to Graphics::Magick::DESTROY, avg 21µs/call |
| 105 | { | ||||
| 106 | |||||
| 107 | # optional crop offset | ||||
| 108 | 3424 | 5.16ms | my $crop_offset = 0; | ||
| 109 | |||||
| 110 | # get original sprite image | ||||
| 111 | 3424 | 10.6ms | my $image = $sprite->{'image'}; | ||
| 112 | |||||
| 113 | # we have to crop the image as we | ||||
| 114 | # otherwise may paint into another | ||||
| 115 | # confined sprite on the canvas | ||||
| 116 | 3424 | 3.48ms | if ($i < $lower_x) | ||
| 117 | { | ||||
| 118 | # calculate the crop offset | ||||
| 119 | 168 | 168µs | $crop_offset = $lower_x - $i; | ||
| 120 | # calculate the new width after cropping | ||||
| 121 | 168 | 2.48ms | 168 | 2.15ms | my $crop_width = $sprite->width - $crop_offset; # spent 2.15ms making 168 calls to OCBNET::Spritesets::Block::width, avg 13µs/call |
| 122 | # create a clone of the sprite | ||||
| 123 | 168 | 25.5ms | 168 | 21.6ms | $image = $image->clone; # spent 21.6ms making 168 calls to Graphics::Magick::clone, avg 129µs/call |
| 124 | # crop the cloned image | ||||
| 125 | 168 | 27.9ms | 336 | 24.0ms | $image->Crop( # spent 21.2ms making 168 calls to Graphics::Magick::Crop, avg 126µs/call
# spent 2.73ms making 168 calls to OCBNET::Spritesets::Block::height, avg 16µs/call |
| 126 | width => $crop_width, | ||||
| 127 | height => $sprite->height, | ||||
| 128 | x => $crop_offset, y => 0 | ||||
| 129 | ); | ||||
| 130 | } | ||||
| 131 | # EO if needs cropping | ||||
| 132 | |||||
| 133 | # draw image on canvas | ||||
| 134 | 3424 | 764ms | 3424 | 618ms | $self->{'image'}->Composite( # spent 618ms making 3424 calls to Graphics::Magick::Composite, avg 181µs/call |
| 135 | y => $top, | ||||
| 136 | image => $image, | ||||
| 137 | compose => 'over', | ||||
| 138 | x => $i + $crop_offset | ||||
| 139 | ); | ||||
| 140 | |||||
| 141 | } | ||||
| 142 | # EO each repeat on the left | ||||
| 143 | |||||
| 144 | # draw the repeating patterns on the right side of the original drawn sprite | ||||
| 145 | 232 | 23.5ms | 336 | 6.79ms | for (my $i = $left + $sprite_width; $i < $upper_x; $i += $sprite_width) # spent 6.79ms making 336 calls to Graphics::Magick::DESTROY, avg 20µs/call |
| 146 | { | ||||
| 147 | |||||
| 148 | # optional crop offset | ||||
| 149 | 3384 | 5.62ms | my $crop_offset = 0; | ||
| 150 | |||||
| 151 | # get original sprite image | ||||
| 152 | 3384 | 10.9ms | my $image = $sprite->{'image'}; | ||
| 153 | |||||
| 154 | # we have to crop the image as we | ||||
| 155 | # otherwise may paint into another | ||||
| 156 | # confined sprite on the canvas | ||||
| 157 | 3384 | 6.57ms | if ($i + $sprite_width > $upper_x) | ||
| 158 | { | ||||
| 159 | # calculate the crop offset | ||||
| 160 | 168 | 231µs | $crop_offset = $upper_x - $i; | ||
| 161 | # create a clone of the sprite | ||||
| 162 | 168 | 21.3ms | 168 | 17.5ms | $image = $image->clone; # spent 17.5ms making 168 calls to Graphics::Magick::clone, avg 104µs/call |
| 163 | # crop the cloned image | ||||
| 164 | 168 | 26.1ms | 336 | 22.4ms | $image->Crop( # spent 19.6ms making 168 calls to Graphics::Magick::Crop, avg 117µs/call
# spent 2.81ms making 168 calls to OCBNET::Spritesets::Block::height, avg 17µs/call |
| 165 | x => 0, y => 0, | ||||
| 166 | width => $crop_offset, | ||||
| 167 | height => $sprite->height | ||||
| 168 | ); | ||||
| 169 | } | ||||
| 170 | |||||
| 171 | # draw image on canvas | ||||
| 172 | 3384 | 704ms | 3384 | 605ms | $self->{'image'}->Composite( # spent 605ms making 3384 calls to Graphics::Magick::Composite, avg 179µs/call |
| 173 | y => $top, x => $i, | ||||
| 174 | compose => 'over', | ||||
| 175 | image => $image | ||||
| 176 | ); | ||||
| 177 | |||||
| 178 | } | ||||
| 179 | # EO each repeat on the right | ||||
| 180 | |||||
| 181 | } | ||||
| 182 | # is repeating on y axis | ||||
| 183 | elsif ($sprite->isRepeatY) | ||||
| 184 | { | ||||
| 185 | |||||
| 186 | # declare boundary vars | ||||
| 187 | 232 | 473µs | my ($lower_y, $upper_y); | ||
| 188 | |||||
| 189 | # check if sprite is fixed | ||||
| 190 | 232 | 3.49ms | 232 | 3.21ms | if ($sprite->isFixedY) # spent 3.21ms making 232 calls to OCBNET::Spritesets::Sprite::isFixedY, avg 14µs/call |
| 191 | { | ||||
| 192 | # get the lower boundary | ||||
| 193 | 168 | 615µs | $lower_y = $offset->{'y'}; | ||
| 194 | # sum up outer height and lower boundary | ||||
| 195 | 168 | 2.37ms | 168 | 16.5ms | $upper_y = $lower_y + $sprite->outerHeight; # spent 16.5ms making 168 calls to OCBNET::Spritesets::Block::outerHeight, avg 98µs/call |
| 196 | } | ||||
| 197 | # sprite has flexible height | ||||
| 198 | else | ||||
| 199 | { | ||||
| 200 | # go behind the top edge | ||||
| 201 | 64 | 191µs | $lower_y = - $sprite_height; | ||
| 202 | # and draw over the bottom edge | ||||
| 203 | 64 | 182µs | $upper_y = $height + $sprite_height; | ||
| 204 | } | ||||
| 205 | # EO if isFixedY | ||||
| 206 | |||||
| 207 | # draw the repeating patterns on the top side of the original drawn sprite | ||||
| 208 | 232 | 24.2ms | 336 | 6.96ms | for (my $i = $top - $sprite_height; $i > $lower_y - $sprite_height; $i -= $sprite_height) # spent 6.96ms making 336 calls to Graphics::Magick::DESTROY, avg 21µs/call |
| 209 | { | ||||
| 210 | |||||
| 211 | # optional crop offset | ||||
| 212 | 3352 | 5.21ms | my $crop_offset = 0; | ||
| 213 | |||||
| 214 | # get original sprite image | ||||
| 215 | 3352 | 10.1ms | my $image = $sprite->{'image'}; | ||
| 216 | |||||
| 217 | # we have to crop the image as we | ||||
| 218 | # otherwise may paint into another | ||||
| 219 | # confined sprite on the canvas | ||||
| 220 | 3352 | 3.33ms | if ($i < $lower_y) | ||
| 221 | { | ||||
| 222 | # calculate the crop offset | ||||
| 223 | 168 | 189µs | $crop_offset = $lower_y - $i; | ||
| 224 | # calculate the new width after cropping | ||||
| 225 | 168 | 2.67ms | 168 | 2.15ms | my $crop_height = $sprite->height - $crop_offset; # spent 2.15ms making 168 calls to OCBNET::Spritesets::Block::height, avg 13µs/call |
| 226 | # create a clone of the sprite | ||||
| 227 | 168 | 23.9ms | 168 | 20.0ms | $image = $image->clone; # spent 20.0ms making 168 calls to Graphics::Magick::clone, avg 119µs/call |
| 228 | # crop the cloned image | ||||
| 229 | 168 | 25.7ms | 336 | 21.7ms | $image->Crop( # spent 19.1ms making 168 calls to Graphics::Magick::Crop, avg 114µs/call
# spent 2.54ms making 168 calls to OCBNET::Spritesets::Block::width, avg 15µs/call |
| 230 | height => $crop_height, | ||||
| 231 | width => $sprite->width, | ||||
| 232 | y => $crop_offset, x => 0 | ||||
| 233 | ); | ||||
| 234 | } | ||||
| 235 | |||||
| 236 | # draw image on canvas | ||||
| 237 | 3352 | 736ms | 3352 | 604ms | $self->{'image'}->Composite( # spent 604ms making 3352 calls to Graphics::Magick::Composite, avg 180µs/call |
| 238 | x => $left, | ||||
| 239 | image => $image, | ||||
| 240 | compose => 'over', | ||||
| 241 | y => $i + $crop_offset | ||||
| 242 | ); | ||||
| 243 | |||||
| 244 | } | ||||
| 245 | # EO each repeat on the top | ||||
| 246 | |||||
| 247 | # draw the repeating patterns on the bottom side of the original drawn sprite | ||||
| 248 | 232 | 49.0ms | 336 | 6.55ms | for (my $i = $top + $sprite_height; $i < $upper_y; $i += $sprite_height) # spent 6.55ms making 336 calls to Graphics::Magick::DESTROY, avg 19µs/call |
| 249 | { | ||||
| 250 | |||||
| 251 | # optional crop offset | ||||
| 252 | 3312 | 5.13ms | my $crop_offset = 0; | ||
| 253 | |||||
| 254 | # get original sprite image | ||||
| 255 | 3312 | 10.3ms | my $image = $sprite->{'image'}; | ||
| 256 | |||||
| 257 | # we have to crop the image as we | ||||
| 258 | # otherwise may paint into another | ||||
| 259 | # confined sprite on the canvas | ||||
| 260 | 3312 | 5.96ms | if ($i + $sprite_height > $upper_y) | ||
| 261 | { | ||||
| 262 | |||||
| 263 | # calculate the crop offset | ||||
| 264 | 168 | 200µs | $crop_offset = $upper_y - $i; | ||
| 265 | # create a clone of the sprite | ||||
| 266 | 168 | 20.8ms | 168 | 17.1ms | $image = $image->clone; # spent 17.1ms making 168 calls to Graphics::Magick::clone, avg 102µs/call |
| 267 | # crop the cloned image | ||||
| 268 | 168 | 24.0ms | 336 | 20.4ms | $image->Crop( # spent 17.6ms making 168 calls to Graphics::Magick::Crop, avg 105µs/call
# spent 2.80ms making 168 calls to OCBNET::Spritesets::Block::width, avg 17µs/call |
| 269 | x => 0, y => 0, | ||||
| 270 | height => $crop_offset, | ||||
| 271 | width => $sprite->width, | ||||
| 272 | ); | ||||
| 273 | } | ||||
| 274 | |||||
| 275 | # draw image on canvas | ||||
| 276 | 3312 | 752ms | 3312 | 587ms | $self->{'image'}->Composite( # spent 587ms making 3312 calls to Graphics::Magick::Composite, avg 177µs/call |
| 277 | x => $left, y => $i, | ||||
| 278 | compose => 'over', | ||||
| 279 | image => $image | ||||
| 280 | ); | ||||
| 281 | } | ||||
| 282 | # EO each repeat on the bottom | ||||
| 283 | |||||
| 284 | } | ||||
| 285 | |||||
| 286 | } | ||||
| 287 | # EO each sprite | ||||
| 288 | |||||
| 289 | } | ||||
| 290 | # EO if fit/edge/stack | ||||
| 291 | |||||
| 292 | } | ||||
| 293 | # EO each area | ||||
| 294 | |||||
| 295 | # return success | ||||
| 296 | 12 | 229µs | return $self; | ||
| 297 | |||||
| 298 | } | ||||
| 299 | # EO sub repeater | ||||
| 300 | |||||
| 301 | #################################################################################################### | ||||
| 302 | #################################################################################################### | ||||
| 303 | 1 | 14µs | 1; |