public function writeIndexed(
        array & $colorRanges, 
        PngPalette $palette, 
        $width, $height) 
    {
        $this->buffer->startChunk("IDAT");

        $uncompressed = '';

        $count = -1;
        $x = 0;

        foreach ($colorRanges as $value) {
            if ($count === -1) {
                $count = $value;
            } else {
                if ($count !== 0) {
                    if ($x === $width) {
                        $x = 0;
                    }
                    if ($x === 0) {
                        $uncompressed .= pack('C', 0); // No filtering
                    }
                    
                    $colorIndex = $palette->lookup[$value];
                    $uncompressed .= str_repeat(pack('C', $colorIndex), $count);
                    $x += $count;
                }
                
                $count = -1;
            }
        }

        $compressed = gzcompress($uncompressed, 2);
        $this->buffer->writeString($compressed);

        $this->buffer->endChunk();
    }
public function writeIndexed(
        array & $colorRanges, 
        PngPalette $palette, 
        $width, $height) 
    {
        $this->buffer->startChunk("IDAT");

        $uncompressed = '';

        $count = -1;
        $x = 0;

        foreach ($colorRanges as $value) {
            if ($count === -1) {
                $count = $value;
            } else {
                if ($count !== 0) {
                    if ($x === $width) {
                        $x = 0;
                    }
                    if ($x === 0) {
                        $uncompressed .= pack('C', 0); // No filtering
                    }
                    
                    $colorIndex = $palette->lookup[$value];
                    $uncompressed .= str_repeat(pack('C', $colorIndex), $count);
                    $x += $count;
                }
                
                $count = -1;
            }
        }

        $compressed = gzcompress($uncompressed, 2);
        $this->buffer->writeString($compressed);

        $this->buffer->endChunk();
    }
public function writeIndexed ( array & $ colorRanges , PngPalette $ palette , $ width , $ height ) { $ this -> buffer -> startChunk ( "IDAT" ) ; $ uncompressed = '' ; $ count = - 1 ; $ x = 0 ; foreach ( $ colorRanges as $ value ) { if ( $ count === - 1 ) { $ count = $ value ; } else { if ( $ count !== 0 ) { if ( $ x === $ width ) { $ x = 0 ; } if ( $ x === 0 ) { $ uncompressed .= pack ( 'C' , 0 ) ; // No filtering } $ colorIndex = $ palette -> lookup [ $ value ] ; $ uncompressed .= str_repeat ( pack ( 'C' , $ colorIndex ) , $ count ) ; $ x += $ count ; } $ count = - 1 ; } } $ compressed = gzcompress ( $ uncompressed , 2 ) ; $ this -> buffer -> writeString ( $ compressed ) ; $ this -> buffer -> endChunk ( ) ; }
Writes an IDAT chunk of indexed image data.

@param array $colorRanges Image data on the format
array(count0, color0, count1, color1, ...)
@param \Jdenticon\Canvas\Png\PngPalette $palette Palette containing the
indexed colors.
@param int $width Image width in pixels.
@param int $height Image height in pixels.
Writes an IDAT chunk of indexed image data .