> 24) & 0xFF; $r = ($color >> 16) & 0xFF; $g = ($color >> 8) & 0xFF; $b = $color & 0xFF; return array($r,$g,$b,$a); } else { $index=imagecolorat($im,$x,$y); $color_tran=imagecolorsforindex($im,$index); return array( $color_tran['red'], $color_tran['green'], $color_tran['blue'], $color_tran['alpha'] ); } } function ImageToColorArray($im){ $ret=array(); $sx=imagesx($im); $sy=imagesy($im); for($y=0;$y<$sy;$y++){ for($x=0;$x<$sx;$x++){ $color=ImageHelperColorAt($im,$x,$y); if($color[3]==127){ array_push($ret,0x8000); } else { $color[0]=($color[0]>>3); $color[1]=($color[1]>>3); $color[2]=($color[2]>>3); $rgb=$color[0]|($color[1]<<5)|($color[2]<<10); array_push($ret,$rgb); } } } return $ret; } function ColorArrayToImage($im,$buffer){ $sx=imagesx($im); $sy=imagesy($im); $bi=0; $trans=imagecolorallocate($im,255,255,255); imagecolortransparent($im,$trans); for($y=0;$y<$sy;$y++){ for($x=0;$x<$sx;$x++){ $bc=$buffer[$bi++]; if($bc&0x8000){ $color=$trans; } else { $r=($bc&0x1F)<<3; $g=(($bc>>5)&0x1F)<<3; $b=(($bc>>10)&0x1F)<<3; $color=imagecolorallocate($im,$r,$g,$b); } imagesetpixel($im,$x,$y,$color); } } } function Color16Invert($color){ $r=$color&0x1F; $g=($color>>5)&0x1F; $b=($color>>10)&0x1F; $r=0x1F-$r; $g=0x1F&~$g; $b=0x1F&~$b; return ($b<<10)|($g<<5)|$r; } function BeautyColors( $color0,//top color $color1,//middle color $color2, //bottom color $beauty ){ if($color0==$color1&&$color0==$color2) return $color1; $rr=$color0&0x1F; $gg=($color0>>5)&0x1F; $bb=($color0>>10)&0x1F; $a=floor(($rr+$gg+$bb)/3); $rr=$color2&0x1F; $gg=($color2>>5)&0x1F; $bb=($color2>>10)&0x1F; $c=floor(($rr+$gg+$bb)/3); $rr=$color1&0x1F; #the ordering (color0,color2,color1) is important here $gg=($color1>>5)&0x1F; $bb=($color1>>10)&0x1F; $b=floor(($rr+$gg+$bb)/3); if($a==$b&&$b==$c) return $color1; $d=($a>$b)?$a-$b:$b-$a; $e=($c>$b)?$c-$b:$b-$c; if($d>=$e)$e=$d; if($beauty==0){ $e>>=1; } $d=0x1F-$e; $rr=floor(($rr*$d)/0x1F); $gg=floor(($gg*$d)/0x1F); $bb=floor(($bb*$d)/0x1F); return $rr|($gg<<5)|($bb<<10); } function Color16ToMonochrome($color){ $r=$color&0x1F; $g=($color>>5)&0x1F; $b=($color>>10)&0x1F; if($r>16||$g>16||$b>16){ return 0x7FFF; } else { return 0; } } function Color16Brighten($color,$value){ $r=$color&0x1F; $g=($color>>5)&0x1F; $b=($color>>10)&0x1F; $r+=$value; $g+=$value; $b+=$value; if($r>31)$r=31; if($g>31)$g=31; if($b>31)$b=31; return $r|($g<<5)|($b<<10); } function LimitColor($color,$value){ $limit=0x1F-$value; $r=($color&0x1F); if($r>$limit) $r=0x1F-($value>>1); return $r|($r<<5)|($r<<10); } function CuteImage($buffer,$sx,$sy){ global $GrafBase; $sp4=array(); for($param=0;$param<0xC80;$param++){ $r1=$param*3; $sp4[0]=$GrafBase[$r1]; $sp4[1]=$GrafBase[$r1+1]; $r4=$GrafBase[$r1+2]; $sp4[2]=$origsp2=($r4>>3)&0x07; $r9=($r4>>1)&0x03; $r5=$r4&0x01; for($r8=1;$r8<$sp4[2];$r8++){ $r2=$r8*3; $r0=$sp4[0]; if(!$r5){ $sp4[$r2]=$sp4[0]-$r8; $r0=$sp4[1]+$r8; } else { $sp4[$r2]=$sp4[0]+1; $r0=$sp4[1]-1; } $sp4[$r2+1]=$r0&0xFF; $r0=$sp4[$r2]; if($r0<=0x3F){ $r0=$sp4[$r2+1]; if($r0>0x3F){ $sp4[2]=$r8-1; break; } } $sp4[$r2+2]=$sp4[2]-$r8; } for($r8=0;$r8<$sp4[2];$r8++){ $r6=$r8*3; $r0=$sp4[$r6+1]; $r1=$r0<<7; $r0=$sp4[$r6]<<1; $index=($r0+$r1)>>1; $xx=$index%64; $y=($index-$xx)/64; for(;$y<$sy;$y+=64){ for($x=$xx;$x<$sx;$x+=64){ $index=$y*$sx+$x; $r1=$buffer[$index]; if(!($r1&0x8000)){ $rgb=array(); $rgb[0]=$r1&0x1F; $rgb[1]=($r1>>5)&0x1F; $rgb[2]=($r1>>10)&0x1F; if($r9>=0){ if($r9>1){ if($r9<=3){ $rgb[0]+=$sp4[$r6+2]; $rgb[1]+=$sp4[$r6+2]; $rgb[2]+=$sp4[$r6+2]; $rgb[0]=min($rgb[0],0x1F); $rgb[1]=min($rgb[1],0x1F); $rgb[2]=min($rgb[2],0x1F); } } else { $r1=($origsp2%3)&0xFF; $r0=$sp4[$r6+2]; if($rgb[$r1]>=$r0) $rgb[$r1]-=$r0; else $rgb[$r1]=0; } } $r0=($rgb[2]<<10)|($rgb[1]<<5)|$rgb[0]; $buffer[$index]=$r0; } } } } } for($i=0;$i>5)&0x1F; $b=($b>>10)&0x1F; $r=($r+$g+$b)/3; $r+=3; #not necessary, but done in tough if($r>31)$r=31; $buffer[$i]=($r<<10)|($r<<5)|$r; } } return $buffer; } function GetGrayTone($color){ $r=(($color)&0x1F)*0x4c; $g=(($color>>5)&0x1F)*0x97; $b=(($color>>10)&0x1F)*0x1d; $gray=($r+$g+$b)>>8; return $gray; } function GrayToneArray($rtone,$gtone,$btone){ $ret=array(); for($i=0;$i<32;$i++){ $r=(($i*$rtone)>>8)&0xFF; $g=(($i*$gtone)>>8)&0xFF; $b=(($i*$btone)>>8)&0xFF; $r=min($r,0x1F); $g=min($g,0x1F); $b=min($b,0x1F); $ret[$i]=$r|($g<<5)|($b<<10); } return $ret; } function PinkImage($buffer,$sx,$sy){ $tones=GrayToneArray(0x1f4,0x14a,0x136); for($i=0;$i>5)&0x1F; $b=($color>>10)&0x1F; if($r&0x03) $r=4+($r&0x1C); if($g&0x03) $g=4+($g&0x1C); if($b&0x03) $b=4+($b&0x1C); if($r<=5)$r=6; if($r>=30)$r=30; if($g<=5)$g=6; if($g>=30)$g=30; if($b<=5)$b=6; if($b>=30)$b=30; return ($b<<10)|($g<<5)|$r; } function CoolTransform($color,$id){ $r=$color&0x1F; $g=($color>>5)&0x1F; $b=($color>>10)&0x1F; if($r>16||$g>16||$b>16){ return 0x7FFF; } else { $r=$g=$b=0; $v1=($id/6)%3; $v2=($id%6); switch($v2){ case 0: $r=0;$g=21-$v1;$b=21-$v1; break; case 1: $r=21-$v1;$g=21-$v1;$b=0; break; case 2: $r=21-$v1;$g=0;$b=21-$v1; break; case 3: $r=23-$v1;$g=0;$b=0; break; case 4: $r=0;$g=0;$b=23-$v1; break; case 5: $r=0;$g=23-$v1;$b=0; break; } return ($b<<10)|($g<<5)|$r; } } function FillEdgesBetter($buffer,$sx,$sy){ $bi=0; for($j=0;$j<$sy;$j++){ for($i=0;$i<$sx;$i++){ $flag=0; $b=$buffer[$bi]; if(!($b&0x8000)){ if($i!=0) $flag|=($buffer[$bi-1]&0x8000); else $flag|=1; if($i!=$sx-1)$flag|=($buffer[$bi+1]&0x8000); else $flag|=1; if($j!=0) $flag|=($buffer[$bi-$sx]&0x8000); else $flag|=1; if($j!=$sy-1)$flag|=($buffer[$bi+$sx]&0x8000); else $flag|=1; if($flag) $buffer[$bi]=0x0000; } $bi++; } } return $buffer; } function FillEdges($buffer,$sx,$sy){ $bi=0; for($j=0;$j<$sy;$j++){ for($i=0;$i<$sx;$i++){ $flag=0; $b=$buffer[$bi]; if(!($b&0x8000)){ if($i!=0) $flag|=($buffer[$bi-1]&0x8000); if($i!=$sx-1)$flag|=($buffer[$bi+1]&0x8000); if($j!=0) $flag|=($buffer[$bi-$sx]&0x8000); if($j!=$sy-1)$flag|=($buffer[$bi+$sx]&0x8000); if($flag) $buffer[$bi]=0x0000; } $bi++; } } return $buffer; } function SmartTransform($c1,$c2){ $tmp=array(); if($c1==$c2) return $c2; $tmp[0]=$c1&0x1F; $tmp[1]=($c1>>5)&0x1F; $tmp[2]=($c1>>10)&0x1F; $tmp[3]=$c2&0x1F; $tmp[4]=($c2>>5)&0x1F; $tmp[5]=($c2>>10)&0x1F; if($tmp[0]>25&&$tmp[1]>25&&$tmp[2]>25) return $c2; if($tmp[3]>25&&$tmp[4]>25&&$tmp[5]>25) return $c2; for($i=0;$i<3;$i++){ $cc0=$tmp[$i]; $cc1=$tmp[$i+3]; $tmp[$i+6]=($cc0>$cc1)?$cc0-$cc1:$cc1-$cc0; } $a=$tmp[6]; $b=$tmp[7]; $c=$tmp[8]; $ret=max($a,max($b,$c)); $ret=0x1F-($ret>>1); $a=floor(($tmp[3]*$ret)/0x1F); $b=floor(($tmp[4]*$ret)/0x1F); $c=floor(($tmp[5]*$ret)/0x1F); return $a|($b<<5)|($c<<10); } function SmartImage($buffer,$sx,$sy){ $buffer=FillEdges($buffer,$sx,$sy); for($j=0;$j<$sy;$j++){ $bi=$j*$sx; $tmp=$buffer[$bi++]; for($i=1;$i<$sx;$i++){ $c=$buffer[$bi]; if(!($c&0x8000)){ $c=SmartTransform($tmp,$c); $buffer[$bi]=$c; $tmp=$c; } $bi++; } } for($j=0;$j<$sx;$j++){ $bi=$j; $tmp=$buffer[$bi]; $bi+=$sx; for($i=1;$i<$sy;$i++){ $c=$buffer[$bi]; if(!($c&0x8000)){ $c=SmartTransform($tmp,$c); $buffer[$bi]=$c; $tmp=$c; } $bi+=$sx; } } for($i=0;$i>5)&0x1F); $b=(($c>>10)&0x1F); $rmax1=gbGetValue(0,1,$r); $rmax3=gbGetValue(0,3,$r); $rmax5=gbGetValue(0,5,$r); $tmin=gbGetValue(4,14,$g); $tmax=gbGetValue(24,29,$g); $nr=gbGetValue($tmin,$tmax,$r)-4; $tmin=gbGetValue(4+$rmax5,14+$rmax3,$b); $tmax=gbGetValue(24+$rmax3,29+$rmax1,$b); $ng=gbGetValue($tmin,$tmax,$g)-4; $tmin=gbGetValue(4+$rmax5,14+$rmax3,$g); $tmax=gbGetValue(24+$rmax3,29+$rmax1,$g); $nb=gbGetValue($tmin,$tmax,$b)-4; return ($nb<<10)|($ng<<5)|$nr; } function TVSafeImage($buffer,$sx,$sy){ for($i=0;$i