コード例 #1
0
ファイル: PNGDataDecoder.php プロジェクト: sasezaki/phppng
 protected function unfilter(ByteArray $ba, $width, $height, $bpp)
 {
     $i = 0;
     for ($y = 0; $y < $height; $y++) {
         switch ($ba[$i++]) {
             case 0:
                 $i += $width * $bpp;
                 break;
             case 1:
                 foreach (range(0, $width * $bpp - 1) as $x) {
                     if ($x - $bpp >= 0) {
                         $ba->offsetSet($i, $ba->offsetGet($i) + $ba->offsetGet($i - $bpp) & 0xff);
                     }
                     $i++;
                 }
                 break;
             case 2:
                 for ($x = 0; $x < $width * $bpp; $x++) {
                     if ($y > 0) {
                         $ba->offsetSet($i, $ba->offsetGet($i) + $ba->offsetGet($i - $width * $bpp - 1) & 0xff);
                     }
                     $i++;
                 }
                 break;
             case 3:
                 for ($x = 0; $x < $width * $bpp; $x++) {
                     $left = $x - $bpp >= 0 ? $ba->offsetGet($i - $bpp) : 0;
                     $above = $y - 1 >= 0 ? $ba->offsetGet($i - $width * $bpp - 1) : 0;
                     $ba->offsetSet($i, $ba->offsetGet($i) + floor(($left + $above) / 2) & 0xff);
                     $i++;
                 }
                 break;
             case 4:
                 for ($x = 0; $x < $width * $bpp; $x++) {
                     $left = $x - $bpp >= 0 ? $ba->offsetGet($i - $bpp) : 0;
                     $above = $y > 0 ? $ba->offsetGet($i - $width * $bpp - 1) : 0;
                     $upper_left = $x - $bpp >= 0 && $y > 0 ? $ba->offsetGet($i - $width * $bpp - 1 - $bpp) : 0;
                     $ba->offsetSet($i, $ba->offsetGet($i) + $this->paethPredictor($left, $above, $upper_left) & 0xff);
                     $i++;
                 }
                 break;
             default:
                 throw new PNGDecodeException('未知のフィルタです。');
         }
     }
 }
コード例 #2
0
ファイル: PHPTinyClient.php プロジェクト: Tombana/NNYv3
     //2 - Disconnect the client by closing the socket
     //3 - Log / Save IP / Ban IP, whatever will do.
     //4 - and terminate thread.
     echo 'Error: LENGTH REFUSED!' . "\n";
 }
 //Okay now the interesting part
 //is the [buffer data] (full size - packet header)
 //greater OR equal the [capsule data] length we have been told earlier?
 if ($BUFFER->size() - 5 >= $length) {
     if ($VERBOSE) {
         echo 'Enough bytes, processing...' . "\n";
     }
     //Awesome we have enough bytes now :D
     //Lets continue the "so waited" code part
     //Copy the 5+length first bytes from the buffer to $CAPSULE.
     $CAPSULE = new ByteArray();
     $CAPSULE->append(substr($BUFFER->getBuffer(), 5, $length));
     //position to 5 and read length bytes
     //PROCESS THE CAPSULE (switch and stuff)
     //-----------------------------------------------
     if ($VERBOSE) {
         echo 'Capsule: ' . $CAPSULE->getBuffer() . "\n";
     }
     while (true) {
         //a loop to parse all CMDs in the capsule
         switch ($CAPSULE->readWord()) {
             //-------------------------
             case PCKT_R_WORLD_EOF:
                 echo '[capsuleHandler] End of world server list' . "\n";
                 break;
                 //-------------------------
コード例 #3
0
ファイル: test.php プロジェクト: shenzhe/php-bytearray
echo "bytes md5:";
echo md5($a);
echo "\n";
var_dump($b4);
$bytearray->compress();
echo "compress\n";
var_dump($bytearray);
$b = $bytearray->toString();
$b2 = new ByteArray($a);
echo $b2->readBoolean();
echo "\n";
echo $b2->readUTF();
echo "\n";
var_dump($b2);
$b3 = new ByteArray($b);
var_dump($b3);
$b3->uncompress();
echo $b3->readBoolean();
echo "\n";
echo $b3->readUTF();
echo "\n";
var_dump($b3);
echo memory_get_usage();
echo "\n";
$ba1 = new ByteArray();
for ($i = 0; $i < 20000; $i++) {
    $ba1->writeUTF("this is a test!!!");
}
echo memory_get_usage();
echo "\n";
var_dump($ba1);