public function writePalette(PngPalette $palette) 
    {
        if ($palette && $palette->isValid) {
            $this->buffer->startChunk("PLTE");

            foreach ($palette->colors as $color) {
                $this->buffer->writeString(
                    pack('C', ($color >> 24) & 0xff) .
                    pack('C', ($color >> 16) & 0xff) .
                    pack('C', ($color >> 8) & 0xff));
            }

            $this->buffer->endChunk();
        }
    }