Faster_Image_B52f1a8_Image_Parser::parseSizeForJPEG PHP Метод

parseSizeForJPEG() защищенный Метод

protected parseSizeForJPEG ( ) : array | boolean
Результат array | boolean
    protected function parseSizeForJPEG()
    {
        $state = null;
        while (true) {
            switch ($state) {
                default:
                    $this->stream->read(2);
                    $state = 'started';
                    break;
                case 'started':
                    $b = $this->getByte();
                    if ($b === false) {
                        return false;
                    }
                    $state = $b == 0xff ? 'sof' : 'started';
                    break;
                case 'sof':
                    $b = $this->getByte();
                    if ($b === 0xe1) {
                        $data = $this->stream->read($this->readInt($this->stream->read(2)) - 2);
                        $stream = new Stream();
                        $stream->write($data);
                        if ($stream->read(4) === 'Exif') {
                            $stream->read(2);
                            $exif = new Faster_Image_B52f1a8_Exif_Parser($stream);
                        }
                        break;
                    }
                    if (in_array($b, range(0xe0, 0xef))) {
                        $state = 'skipframe';
                        break;
                    }
                    if (in_array($b, array_merge(range(0xc0, 0xc3), range(0xc5, 0xc7), range(0xc9, 0xcb), range(0xcd, 0xcf)))) {
                        $state = 'readsize';
                        break;
                    }
                    if ($b == 0xff) {
                        $state = 'sof';
                        break;
                    }
                    $state = 'skipframe';
                    break;
                case 'skipframe':
                    $skip = $this->readInt($this->stream->read(2)) - 2;
                    $this->stream->read($skip);
                    $state = 'started';
                    break;
                case 'readsize':
                    $c = $this->stream->read(7);
                    $size = array($this->readInt(substr($c, 5, 2)), $this->readInt(substr($c, 3, 2)));
                    if (isset($exif) && $exif->isRotated()) {
                        return array_reverse($size);
                    }
                    return $size;
            }
        }
        return false;
    }