13declare(strict_types=1);
15namespace pocketmine\network\mcpe\protocol\types;
26 public const MAX_HEIGHT = 128;
27 public const MAX_WIDTH = 128;
35 private array $pixels;
36 private ?
string $encodedPixelCache =
null;
44 foreach($pixels as $row){
45 if($rowLength ===
null){
46 $rowLength = count($row);
47 }elseif(count($row) !== $rowLength){
48 throw new \InvalidArgumentException(
"All rows must have the same number of pixels");
51 if($rowLength ===
null){
52 throw new \InvalidArgumentException(
"No pixels provided");
54 if($rowLength > self::MAX_WIDTH){
55 throw new \InvalidArgumentException(
"Image width must be at most " . self::MAX_WIDTH .
" pixels wide");
57 if(count($pixels) > self::MAX_HEIGHT){
58 throw new \InvalidArgumentException(
"Image height must be at most " . self::MAX_HEIGHT .
" pixels tall");
60 $this->height = count($pixels);
61 $this->width = $rowLength;
62 $this->pixels = $pixels;
65 public function getWidth() : int{ return $this->width; }
67 public function getHeight() : int{ return $this->height; }
73 public function getPixels() : array{ return $this->pixels; }
76 if($this->encodedPixelCache === null){
78 for($y = 0; $y < $this->height; ++$y){
79 for($x = 0; $x < $this->width; ++$x){
81 $serializer->putUnsignedVarInt(Binary::flipIntEndianness($this->pixels[$y][$x]->toRGBA()));
84 $this->encodedPixelCache = $serializer->getBuffer();
87 $output->put($this->encodedPixelCache);
95 if($width > self::MAX_WIDTH){
98 if($height > self::MAX_HEIGHT){
103 for($y = 0; $y < $height; ++$y){
104 for($x = 0; $x < $width; ++$x){
105 $pixels[$y][$x] = Color::fromRGBA(Binary::flipIntEndianness($input->getUnsignedVarInt()));
109 return new self($pixels);
static decode(BinaryStream $input, int $height, int $width)
__construct(array $pixels)