count() 공개 메소드

public count ( $force = false )
예제 #1
0
 /**
  * @covers ColorThief\VBox::count
  */
 public function testCount()
 {
     $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 = 130 >> ColorThief::RSHIFT;
     $this->vbox->b2 = 158 >> ColorThief::RSHIFT;
     //$pixels = array(0xE1BE9E, 0xC8BD9E, 0xFFBD9E, 0xE1329E, 0xE1C89E, 0xE1BD64, 0xE1BDC8);
     $this->vbox->histo = array(29427 => 1, 26355 => 1, 32499 => 1, 28883 => 1, 29491 => 1, 29420 => 1, 29433 => 1);
     $this->assertEquals(1, $this->vbox->count());
     $this->vbox->histo[29427] = 2;
     $this->vbox->histo[30449] = 1;
     // Previous result should be cached.
     $this->assertEquals(1, $this->vbox->count());
     // Forcing refresh should now give the right result
     $this->assertEquals(3, $this->vbox->count(true));
 }
예제 #2
0
 /**
  * @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);
 }
예제 #3
0
 /**
  * @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);
 }