ColorThief\ColorThief::getColorsFromIndex PHP Method

getColorsFromIndex() public static method

Get red, green and blue components from reduced-space color index for a pixel
public static getColorsFromIndex ( integer $index, integer $rightShift = self::RSHIFT, integer $sigBits = 8 ) : array
$index integer
$rightShift integer
$sigBits integer
return array
    public static function getColorsFromIndex($index, $rightShift = self::RSHIFT, $sigBits = 8)
    {
        $mask = (1 << $sigBits) - 1;
        $red = ($index >> 2 * $sigBits & $mask) >> $rightShift;
        $green = ($index >> $sigBits & $mask) >> $rightShift;
        $blue = ($index & $mask) >> $rightShift;
        return array($red, $green, $blue);
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * @dataProvider provide8bitsColorIndex
  */
 public function testGetColorsFromIndex8bits($r, $g, $b, $index)
 {
     $this->assertSame(array($r, $g, $b), ColorThief::getColorsFromIndex($index, 0));
 }