/** * @covers ColorThief\VBox::longestAxis */ public function testLongestAxis() { $this->vbox->r1 = 225 >> ColorThief::RSHIFT; $this->vbox->r2 = 247 >> ColorThief::RSHIFT; $this->vbox->g1 = 180 >> ColorThief::RSHIFT; $this->vbox->g2 = 189 >> ColorThief::RSHIFT; $this->vbox->b1 = 180 >> ColorThief::RSHIFT; $this->vbox->b2 = 228 >> ColorThief::RSHIFT; $this->assertEquals('b', $this->vbox->longestAxis()); $this->vbox->g1 = 110 >> ColorThief::RSHIFT; $this->assertEquals('g', $this->vbox->longestAxis()); $this->vbox->r1 = 10 >> ColorThief::RSHIFT; $this->assertEquals('r', $this->vbox->longestAxis()); }
/** * @covers ColorThief\VBox::contains */ public function testContains() { $this->vbox->r1 = 225 >> ColorThief::RSHIFT; $this->vbox->r2 = 247 >> ColorThief::RSHIFT; $this->vbox->g1 = 180 >> ColorThief::RSHIFT; $this->vbox->g2 = 189 >> ColorThief::RSHIFT; $this->vbox->b1 = 158 >> ColorThief::RSHIFT; $this->vbox->b2 = 158 >> ColorThief::RSHIFT; $this->assertTrue($this->vbox->contains(array(225, 190, 158))); $this->assertFalse($this->vbox->contains(array(200, 189, 158))); $this->assertFalse($this->vbox->contains(array(255, 189, 158))); $this->assertFalse($this->vbox->contains(array(225, 50, 158))); $this->assertFalse($this->vbox->contains(array(225, 200, 158))); $this->assertFalse($this->vbox->contains(array(225, 189, 100))); $this->assertFalse($this->vbox->contains(array(225, 189, 200))); }
/** * @param array $histo * @param VBox $vBox * @return array|void */ private static function medianCutApply($histo, $vBox) { if (!$vBox->count()) { return; } // If the vbox occupies just one element in color space, it can't be split if ($vBox->count() == 1) { return array($vBox->copy()); } // Select the longest axis for splitting $cutColor = $vBox->longestAxis(); // Find the partial sum arrays along the selected axis. list($total, $partialSum) = static::sumColors($cutColor, $histo, $vBox); return static::doCut($cutColor, $vBox, $partialSum, $total); }
/** * @param array $histo * @param VBox $vBox * @return array|void */ private static function medianCutApply($histo, $vBox) { if (!$vBox->count()) { return; } // If the vbox occupies just one element in color space, it can't be split if ($vBox->count() == 1) { return array($vBox->copy()); } // Select the longest axis for splitting $redWidth = $vBox->r2 - $vBox->r1 + 1; $greenWidth = $vBox->g2 - $vBox->g1 + 1; $blueWidth = $vBox->b2 - $vBox->b1 + 1; $maxWidth = max($redWidth, $greenWidth, $blueWidth); // Determine the cut planes switch ($maxWidth) { case $redWidth: list($total, $partialSum, $favorColor) = self::sumColors(self::favorRed(), $histo, $vBox); break; case $greenWidth: list($total, $partialSum, $favorColor) = self::sumColors(self::favorGreen(), $histo, $vBox); break; case $blueWidth: default: list($total, $partialSum, $favorColor) = self::sumColors(self::favorBlue(), $histo, $vBox); break; } return static::doCut($favorColor, $vBox, $partialSum, $total); }