in reply to Re^4: Double the speed of Imager->setpixel
in thread Double the speed of Imager->setpixel
What does that mean?
Code fragment is only reached if illuminated interval at particular latitude doesn't cross map border. Won't happen at 12 GMT. It also means replacing that loop won't affect time I posted because of 12 GMT chosen for a test.
Looks like I robbed humanity of 45s (24 hours / 1920) of their precious daytime, off by 1 error in patch above. Fixed below.
I also came to significantly faster solution, but have to decide what to do with rounding errors and glitches which are possible very close to equinoxes with maths as implemented in this module. Unseen possible stray pixel with current solution, but unacceptable if polygon lines jump from pole to pole for daytime illumination area. May lead to a few heart attacks among astronomers or geographers etc. But absolutely don't wont to re-do all trigonometry from scratch, need more time for a hack which would seem reliable enough.
--- WorldMap.pm.old Fri Jun 17 10:33:43 2016 +++ WorldMap.pm Wed Dec 14 12:18:17 2022 @@ -500,7 +500,7 @@ my ($wtab, $noon, $width, $height) = @_; my $illumMap = Imager->new(ysize => $height, xsize => $width); $illumMap = $illumMap->convert(preset => 'addalpha'); - my $day = Imager::Color->new(255, 255, 255, 10); + my $day_p = pack 'C4', 255, 255, 255, 10; my ($i, $j, $oh, $nl, $nh); for ($i = 0; $i < $height; $i++) { @@ -510,16 +510,13 @@ $oh = ($nh - $nl) + 1; if (($nl + $oh) > $width) { - for ($j = $nl; $j < $width; $j++) { - $illumMap->setpixel(x => $j, y => $i, color => $d +ay); - } - for ($j = 0; $j < ((($nl + $oh) - $width) + 1); $j++) + { - $illumMap->setpixel(x => $j, y => $i, color => $d +ay); - } + $illumMap->setscanline(x => $nl, y => $i, + pixels => $day_p x ($width - $nl)); + $illumMap->setscanline(x => 0, y => $i, + pixels => $day_p x ($nl + $oh - $width + 1)); } else { - for ($j = $nl; $j < (($nl + $oh) + 1); $j++) { - $illumMap->setpixel(x => $j, y => $i, color => $d +ay); - } + $illumMap->setscanline(x => $nl, y => $i, + pixels => $day_p x ($oh + 1)); } } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^6: Double the speed of Imager->setpixel
by Anonymous Monk on Dec 14, 2022 at 16:01 UTC | |
Re^6: Double the speed of Imager->setpixel
by Anonymous Monk on Dec 17, 2022 at 15:00 UTC |