note 36239 modified in function.imageline by didou

From: Date: Thu, 02 Oct 2003 09:03:03 +0000
Subject: note 36239 modified in function.imageline by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-57594@lists.php.net to get a copy of this message
# antialiased draw_line function (1.x sec. fast) # here is a drawLine() posted by nanobot at chipx86 dot com # on php.net and enhanced/optimized by myself :) # here are some changes i made: # 1. changed for true-color images (no index_var used) # 2. changed rgb extraction to logical shift # 3. changed <= comparisons to < an function drawQSLine ($image,$x1,$y1,$x2,$y2,$r,$g,$b) { $icr=$r; $icg=$g; $icb=$b; $dcol = ImageColorAllocate ($image,$icr,$icg,$icb); if ($y1 == $y2) imageline ($image,$x1,$y1,$x2,$y1,$dcol); else if ($x1 == $x2) { imageline ($image,$x1,$y1,$x1,$y2,$dcol); } else { $m = ($y2 - $y1) / ($x2 - $x1); $b = $y1 - $m * $x1; if (abs ($m) <2) { $x = min ($x1,$x2); $endx = max ($x1,$x2)+1; while ($x < $endx) { $y = $m * $x + $b; $y == floor ($y) ? $ya = 1 : $ya = $y - floor ($y); $yb = ceil ($y) - $y; $trgb = ImageColorAt($image,$x,floor($y)); $tcr = ($trgb >> 16) & 0xFF; $tcg = ($trgb >> 8) & 0xFF; $tcb = $trgb & 0xFF; $tcr = $tcr * $ya + $icr * $yb; $tcg = $tcg * $ya + $icg * $yb; $tcb = $tcb * $ya + $icb * $yb; imagesetpixel ($image,$x,floor ($y),imagecolorallocate ($image,$tcr,$tcg,$tcb)); $trgb = ImageColorAt($image,$x,ceil($y)); $tcr = ($trgb >> 16) & 0xFF; $tcg = ($trgb >> 8) & 0xFF; $tcb = $trgb & 0xFF; $tcr = $tcr * $yb + $icr * $ya; $tcg = $tcg * $yb + $icg * $ya; $tcb = $tcb * $yb + $icb * $ya; imagesetpixel ($image,$x,ceil ($y),imagecolorallocate ($image,$tcr,$tcg,$tcb)); $x ++; } # while_x_end } # if_end else { # else_abs_end $y = min ($y1,$y2); $endy = max ($y1,$y2)+1; while ($y < $endy) { $x = ($y - $b) / $m; $x == floor ($x) ? $xa = 1 : $xa = $x - floor ($x); $xb = ceil ($x) - $x; $trgb = ImageColorAt($image,floor($x),$y); $tcr = ($trgb >> 16) & 0xFF; $tcg = ($trgb >> 8) & 0xFF; $tcb = $trgb & 0xFF; $tcr = $tcr * $xa + $icr * $xb; $tcg = $tcg * $xa + $icg * $xb; $tcb = $tcb * $xa + $icb * $xb; imagesetpixel ($image,floor ($x),$y,imagecolorallocate ($image,$tcr,$tcg,$tcb)); $trgb = ImageColorAt($image,ceil($x),$y); $tcr = ($trgb >> 16) & 0xFF; $tcg = ($trgb >> 8) & 0xFF; $tcb = $trgb & 0xFF; $tcr = $tcr * $xb + $icr * $xa; $tcg = $tcg * $xb + $icg * $xa; $tcb = $tcb * $xb + $icb * $xa; imagesetpixel ($image,ceil ($x),$y,imagecolorallocate ($image,$tcr,$tcg,$tcb)); $y ++; }# while_y_end }# else_abs_end }# else_y=y_x=x_end }# drawOSLine_end --was-- # antialiased draw_line function (1.x sec. fast) # here is a drawLine() posted by nanobot@chipx86.com # on php.net and enhanced/optimized by myself :) # here are some changes i made: # 1. changed for true-color images (no index_var used) # 2. changed rgb extraction to logical shift # 3. changed <= comparisons to < an function drawQSLine ($image,$x1,$y1,$x2,$y2,$r,$g,$b) { $icr=$r; $icg=$g; $icb=$b; $dcol = ImageColorAllocate ($image,$icr,$icg,$icb); if ($y1 == $y2) imageline ($image,$x1,$y1,$x2,$y1,$dcol); else if ($x1 == $x2) { imageline ($image,$x1,$y1,$x1,$y2,$dcol); } else { $m = ($y2 - $y1) / ($x2 - $x1); $b = $y1 - $m * $x1; if (abs ($m) <2) { $x = min ($x1,$x2); $endx = max ($x1,$x2)+1; while ($x < $endx) { $y = $m * $x + $b; $y == floor ($y) ? $ya = 1 : $ya = $y - floor ($y); $yb = ceil ($y) - $y; $trgb = ImageColorAt($image,$x,floor($y)); $tcr = ($trgb >> 16) & 0xFF; $tcg = ($trgb >> 8) & 0xFF; $tcb = $trgb & 0xFF; $tcr = $tcr * $ya + $icr * $yb; $tcg = $tcg * $ya + $icg * $yb; $tcb = $tcb * $ya + $icb * $yb; imagesetpixel ($image,$x,floor ($y),imagecolorallocate ($image,$tcr,$tcg,$tcb)); $trgb = ImageColorAt($image,$x,ceil($y)); $tcr = ($trgb >> 16) & 0xFF; $tcg = ($trgb >> 8) & 0xFF; $tcb = $trgb & 0xFF; $tcr = $tcr * $yb + $icr * $ya; $tcg = $tcg * $yb + $icg * $ya; $tcb = $tcb * $yb + $icb * $ya; imagesetpixel ($image,$x,ceil ($y),imagecolorallocate ($image,$tcr,$tcg,$tcb)); $x ++; } # while_x_end } # if_end else { # else_abs_end $y = min ($y1,$y2); $endy = max ($y1,$y2)+1; while ($y < $endy) { $x = ($y - $b) / $m; $x == floor ($x) ? $xa = 1 : $xa = $x - floor ($x); $xb = ceil ($x) - $x; $trgb = ImageColorAt($image,floor($x),$y); $tcr = ($trgb >> 16) & 0xFF; $tcg = ($trgb >> 8) & 0xFF; $tcb = $trgb & 0xFF; $tcr = $tcr * $xa + $icr * $xb; $tcg = $tcg * $xa + $icg * $xb; $tcb = $tcb * $xa + $icb * $xb; imagesetpixel ($image,floor ($x),$y,imagecolorallocate ($image,$tcr,$tcg,$tcb)); $trgb = ImageColorAt($image,ceil($x),$y); $tcr = ($trgb >> 16) & 0xFF; $tcg = ($trgb >> 8) & 0xFF; $tcb = $trgb & 0xFF; $tcr = $tcr * $xb + $icr * $xa; $tcg = $tcg * $xb + $icg * $xa; $tcb = $tcb * $xb + $icb * $xa; imagesetpixel ($image,ceil ($x),$y,imagecolorallocate ($image,$tcr,$tcg,$tcb)); $y ++; }# while_y_end }# else_abs_end }# else_y=y_x=x_end }# drawOSLine_end http://www.php.net/manual/en/function.imageline.php

« previous php.notes (#57594) next »