@param array $blocks The array returned by decode.

@return array Array of images each containing 1 of each frames of the original image.
422137
public function splitFrames($blocks){
        $images = array();
        if (isset($blocks['frames'])){
            foreach($blocks['frames'] as $a=>$unused){
                $images[$a] = $blocks;
                unset($images[$a]['frames']); // remove all frames.
                foreach($blocks['frames'] as $b=>$frame){
                    if($a===$b){
                        $images[$a]['frames'][0] = $frame; // Re-add frames but use only 1 frame and discard others
                        break;
                    }
                }
            }
        }
        return $images;
    }
846966
function(blocks) {
  var blockarr = blocks;
  if (!(blockarr instanceof Array)) {
    blockarr = [blockarr];
  }
  return {format: 'section', blocks: blockarr};
}
537773
public function decodeToBlocks($bytes){
        $bytes->setPosition(0);
        $blocks = array();

        // Header block
        $blocks['header'] = $bytes->bite(6);

        // Logical screen descriptor block
        $part = $bytes->bite(2); // canvass w
        $hex = $part;
        $part = $bytes->bite(2); // canvass h
        $hex .= $part;
        $part = $bytes->bite(1); // packed field
        $hex .= $part;
        $bin = $this->_fixSize($this->_hexToBin($part),8);
        $globalColorTableFlag = bindec(substr($bin, 0 ,1));
        $sizeOfGlobalColorTable = bindec(substr($bin, 5 ,3));

        $part = $bytes->bite(1); // backgroundColorIndex
        $hex .= $part;
        $part = $bytes->bite(1); // pixelAspectRatio
        $hex .= $part;
        $blocks['logicalScreenDescriptor'] = $hex;

        // Global color table is optional so check its existence
        if($globalColorTableFlag > 0){
            // Formula: 3 * (2^(N+1))
            $colorTableLength = 3*(pow(2,($sizeOfGlobalColorTable+1)));
            $part = $bytes->bite($colorTableLength);
            $blocks['globalColorTable'] = $part;
        }


        $commentC = $plainTextC = $appCount = $gce = $dc = 0; // index count
        while(!$bytes->isEnd()){
            $part = $bytes->bite(1);

            if('21'===$part){ // block tests
                $hex = $part;
                $part = $bytes->bite(1);
                if('ff'===$part) { // App extension block
                    $hex .= $part;
                    $part = $bytes->bite(1); // app name length should be 0x0b or int 11 but we check anyways
                    $size = hexdec($part); // turn it to int
                    $hex .= $part;
                    $part = $bytes->bite($size); // app name
                    $hex .= $part;
                    while (!$bytes->isEnd()) { // loop thru all app sub blocks
                        $nextSize = $bytes->bite(1);
                        if($nextSize !== '00'){
                            $hex .= $nextSize;
                            $size = hexdec($nextSize);
                            $part = $bytes->bite($size);
                            $hex .= $part;
                        } else {
                            $hex .= $nextSize;
                            $blocks['applicationExtension-'.$appCount] = $hex;
                            break;
                        }

                    }

                    $appCount++;
                } else if('f9'===$part){ // graphic
                    $hex .= $part;
                    $part = $bytes->bite(1); // size
                    $hex .= $part;
                    $part = $bytes->bite(1); // packed field
                    $hex .= $part;
                    $part = $bytes->bite(2); // delay time
                    $hex .= $part;
                    $part = $bytes->bite(1); // trans color index
                    $hex .= $part;
                    $part = $bytes->bite(1); // terminator
                    $hex .= $part;
                    $blocks['graphicControlExtension-'.$gce] = $hex;
                    $gce++;
                } else if('01' === $part){ // plain text ext
                    $hex .= $part;

                    while (!$bytes->isEnd()) { // loop thru all app sub blocks
                        $nextSize = $bytes->bite(1);
                        if($nextSize !== '00'){
                            $hex .= $nextSize;
                            $size = hexdec($nextSize);
                            $part = $bytes->bite($size);
                            $hex .= $part;
                        } else {
                            $hex .= $nextSize;
                            $blocks['plainTextExtension-'.$plainTextC] = $hex;
                            break;
                        }

                    }
                    $plainTextC++;
                } else if('fe' === $part){ // comment ext
                    $hex .= $part;

                    while (!$bytes->isEnd()) { // loop thru all app sub blocks
                        $nextSize = $bytes->bite(1);
                        if($nextSize !== '00'){
                            $hex .= $nextSize;
                            $size = hexdec($nextSize);
                            $part = $bytes->bite($size);
                            $hex .= $part;
                        } else {
                            $hex .= $nextSize;
                            $blocks['commentExtension-'.$commentC] = $hex;
                            break;
                        }

                    }
                    $commentC++;
                }
            } else if ('2c'===$part){ // image descriptors
                $hex = $part;
                $part = $bytes->bite(2); // imageLeft
                $hex .= $part;
                $part = $bytes->bite(2); // imageTop
                $hex .= $part;
                $part = $bytes->bite(2); // imageWidth
                $hex .= $part;
                $part = $bytes->bite(2); // imageHeight
                $hex .= $part;
                $part = $bytes->bite(1); // packed field
                $hex .= $part;
                $blocks['imageDescriptor-'.$dc] = $hex;
                $bin = $this->_fixSize($this->_hexToBin($part), 8);
                $localColorTableFlag = bindec(substr($bin, 0, 1));
                $sizeOfLocalColorTable = bindec(substr($bin, 5, 3));

                //LC
                if($localColorTableFlag){
                    // Formula: 3 * (2^(N+1))
                    $localColorTableLen = 3 * (pow(2, ($sizeOfLocalColorTable + 1)));
                    $part = $bytes->bite($localColorTableLen);
                    $blocks['localColorTable-'.$dc] = $part;
                }

                // Image data
                $part = $bytes->bite(1); // LZW code
                $hex = $part;
                while ($bytes->isEnd()===false) {
                    $nextSize = $bytes->bite(1);
                    $hex .= $nextSize;
                    if($nextSize !== '00') {
                        $subBlockLen = hexdec($nextSize);
                        $subBlock    = $bytes->bite($subBlockLen);
                        $hex .= $subBlock;
                    } else {
                        $blocks['imageData-'.$dc] = $hex;
                        break;
                    }

                }

                $dc++;

            } else {
                $blocks['trailer'] = $part;
                break;
            }
        }
        if($blocks['trailer']!=='3b'){
            throw new \Exception('Error decoding GIF. Stopped at '.$bytes->getPosition().'. Length is '.$bytes->length().'.');
        }

        return $blocks;
    }
1339654
public function sortBlocks(array $blocks)
    {
        // Determine hierarchy of ownership first
        $hierarchy = array();
        foreach ($blocks as $block) {
            if ($block instanceof BlockOwnerInterface) {
                $key = ($block->getParent()) ? array_search($block->getParent()->getId(), $hierarchy) : false;
                $pos = ($key) ? $key-1 : count($hierarchy)+1;
                $hierarchy[$pos] = $block->getId();
            }
        }
        $hierarchy = array_flip($hierarchy); // Flip it for easier lookup by parentId as key.

        usort($blocks, function ($a, $b) use ($hierarchy) {
            if ($a->getOwner() === null || $b->getOwner() === null) {
                return 0;
            }

            // when blocks sort positions are equal and they have different
            // owners apply inherited sorting
            if ($a->getSort() === $b->getSort() && $a->getOwner()->getId() != $b->getOwner()->getId()) {
                return ($hierarchy[$a->getOwner()->getId()] < $hierarchy[$b->getOwner()->getId()]) ? 1 : -1;
            }

            return ($a->getSort() < $b->getSort()) ? -1 : 1;
        });

        return $blocks;
    }
1137406
public function getBlocks()
    {
        if ($this->blocks !== null) {
            return $this->blocks;
        }
        $this->findBrocks();
        return $this->blocks;
    }
88925
protected function loadBlocks()
    {
        if ($this->isLoaded)
            return;

        $blockOwners = $this->getBlockOwners();
        $blocks = array();

        foreach ($blockOwners as $blockOwner) {
            $version = $this->getVersion($blockOwner->getId());

            $owned = $this->blockManager->findByOwner($blockOwner, $version);

            $blocks = array_merge($blocks, $owned);
        }

        $blocks = $this->blockManager->sortBlocks(array_merge($blocks, $blockOwners));
        $cacheKey = $this->getCacheKey();

        $this->blockCache[$cacheKey] = array_filter($blocks, function($item) {
            return ($item instanceof DocumentBlock) ? false : true;
        });

        $this->isLoaded = true;

        return $this;
    }
1367423
private function block($nodes)
    {
        $code = $this->walk($nodes, 0);
        $key = ucfirst(md5($code));

        if (!isset($this->blocks[$key])) {
            $this->blocks[$key] = sprintf($this->prepare(self::BLOCK_FUNCTION, 0), $key, $code);
        }

        return $key;
    }
536219
public function findByBlock($block)
    {
        if ($block instanceof Block) {
            $block = $block->getBlockID();
        } elseif ($block instanceof BlockController) {
            $block = $block->getBlockObject()->getBlockID();
        }

        return $this->findBy([
            'block_id' => $block
        ]);
    }
919653
public function getBlockPropertySet(Block $block)
	{
		$blockPropertySet = new BlockPropertySet();
		
		/* @var $blockProperty \Supra\Package\Cms\Entity\BlockProperty */
		foreach ($this as $blockProperty) {
			if ($blockProperty->getBlock()->equals($block)) {
				$blockPropertySet->append($blockProperty);
			}
		}
		
		return $blockPropertySet;
	}
1292721
protected function _prepareBlocks()
    {
        $cacheKey = "{$this->_View->theme}_{$this->_machineName}";
        $blocks = TableRegistry::get('Block.Blocks')
            ->find('all')
            ->cache($cacheKey, 'blocks')
            ->contain(['Roles', 'BlockRegions'])
            ->matching('BlockRegions', function ($q) {
                return $q->where([
                    'BlockRegions.theme' => $this->_View->theme(),
                    'BlockRegions.region' => $this->_machineName,
                ]);
            })
            ->where(['Blocks.status' => 1])
            ->order(['BlockRegions.ordering' => 'ASC']);

        $blocks->sortBy(function ($block) {
            return $block->region->ordering;
        }, SORT_ASC);

        // remove blocks that cannot be rendered based on current request.
        $blocks = $blocks->filter(function ($block) {
            return $this->_filterBlock($block) && $block->renderable();
        });

        $this->blocks($blocks);
    }
281762
private function seedBlock($blockTypes, $languages, $users, $contents)
    {
        $blocks = [];
        for ($x = 0; $x < self::RANDOM_BLOCKS; $x++) {
            $block    = $this->seedRandomBlock(
                $blockTypes->random(),
                $languages,
                $users,
                $contents
            );
            $blocks[] = $block;
        }

        return $blocks;
    }
1328633
public BlockInfo[] getParityBlocks(BlockInfo[] blocks) {
    int numBlocks = (blocks.length / numStripeBlocks) * numParityBlocks
        + ((blocks.length % numStripeBlocks == 0) ? 0 : numParityBlocks);
    BlockInfo[] parityBlocks = new BlockInfo[numBlocks];
    int pos = 0;
    int parityEnd = numParityBlocks;
    for (int i = 0; i < numBlocks; i++) {
      parityBlocks[i] = blocks[pos];
      pos++;
      if (pos == parityEnd) {
        pos += numDataBlocks;
        parityEnd += numStripeBlocks;
      }
    }
    return parityBlocks;
  }
70854
private static function debugCheckLooksLikeBlocksArray(iterable $blocks): bool
    {
        $result = true;

        foreach ($blocks as $index => $block) {
            $result = $result &&
                is_int($index) === true &&
                is_array($block) === true &&
                static::debugHasKnownBlockType($block) === true;
        }

        return $result;
    }
242948
public function getBlocks()
    {
        $sanitizedBlocks = [];

        foreach ($this->blocks as $block) {
            $sanitizedBlock = $this->handler->sanitizeBlock($block['type'], $block['data']);
            if (!empty($sanitizedBlock)) {
                array_push($sanitizedBlocks, $sanitizedBlock);
            }
        }

        return $sanitizedBlocks;
    }
1219059
protected function createBlocks(BlockInterface $block)
    {
        $content = [];
        $content['id'] = $block->getId();
        $content['name'] = $block->getName();
        $content['enabled'] = $block->getEnabled();
        $content['position'] = $block->getPosition();
        $content['settings'] = $block->getSettings();
        $content['type'] = $block->getType();
        $content['created_at'] = $block->getCreatedAt()->format('U');
        $content['updated_at'] = $block->getUpdatedAt()->format('U');
        $content['blocks'] = [];

        foreach ($block->getChildren() as $child) {
            $content['blocks'][] = $this->createBlocks($child);
        }

        return $content;
    }
1172618
public function getBlockTypeSets()
    {
        $db = Loader::db();
        $list = array();
        $r = $db->Execute(
                'select btsID from BlockTypeSetBlockTypes where btID = ? order by displayOrder asc',
                array($this->getBlockTypeID()));
        while ($row = $r->FetchRow()) {
            $list[] = BlockTypeSet::getByID($row['btsID']);
        }
        $r->Close();

        return $list;
    }
1196072
public function getWiths() {
		$ret = array ();
		foreach($this->blockManifest as $block) {
			if($block->isWith()) {
				$ret[] = $block;
			}
		}

		return $ret;
	}