public function count($force = false) { if (!$this->count_set || $force) { $npix = 0; // Select the fastest way (i.e. with the fewest iterations) to count // the number of pixels contained in this vbox. if ($this->volume() > count($this->histo)) { // Iterate over the histogram if the size of this histogram is lower than the vbox volume foreach ($this->histo as $rgb => $count) { $rgb_array = ColorThief::getColorsFromIndex($rgb, 0, ColorThief::SIGBITS); if ($this->contains($rgb_array, 0)) { $npix += $count; } } } else { // Or iterate over points of the vbox if the size of the histogram is greater than the vbox volume for ($i = $this->r1; $i <= $this->r2; $i++) { for ($j = $this->g1; $j <= $this->g2; $j++) { for ($k = $this->b1; $k <= $this->b2; $k++) { $index = ColorThief::getColorIndex($i, $j, $k); if (isset($this->histo[$index])) { $npix += $this->histo[$index]; } } } } } $this->count = $npix; $this->count_set = true; } return $this->count; }