Skip to content

Commit 84a9676

Browse files
committed
Rename some variables to improve legibility
1 parent 536d540 commit 84a9676

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

lib/ColorThief/ColorThief.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,8 @@ private static function vboxFromHistogram(array $histo)
262262
$rgbMax = [-PHP_INT_MAX, -PHP_INT_MAX, -PHP_INT_MAX];
263263

264264
// find min/max
265-
foreach ($histo as $index => $count) {
266-
$rgb = static::getColorsFromIndex($index, self::SIGBITS);
265+
foreach ($histo as $bucketIndex => $count) {
266+
$rgb = static::getColorsFromIndex($bucketIndex, self::SIGBITS);
267267

268268
// For each color components
269269
for ($i = 0; $i < 3; $i++) {
@@ -285,7 +285,7 @@ private static function vboxFromHistogram(array $histo)
285285
* @param array $partialSum
286286
* @param int $total
287287
*
288-
* @return array
288+
* @return array|void
289289
*/
290290
private static function doCut($color, $vBox, $partialSum, $total)
291291
{

lib/ColorThief/VBox.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ public function avg($force = false)
110110
ColorThief::SIGBITS
111111
);
112112

113+
// The bucket values need to be multiplied by $mult to get the RGB values.
114+
// Can't use a left shift here, as we're working with a floating point number to put the value at the bucket's midpoint.
113115
$hval = isset($this->histo[$bucketIndex]) ? $this->histo[$bucketIndex] : 0;
114116
$ntot += $hval;
115117
$rsum += ($hval * ($redBucket + 0.5) * $mult);
@@ -143,19 +145,20 @@ public function avg($force = false)
143145
return $this->avg;
144146
}
145147

146-
public function contains(array $pixel, $rshift = ColorThief::RSHIFT)
148+
public function contains(array $rgbValue, $rshift = ColorThief::RSHIFT)
147149
{
148-
$rval = $pixel[0] >> $rshift;
149-
$gval = $pixel[1] >> $rshift;
150-
$bval = $pixel[2] >> $rshift;
150+
// Get the buckets from the RGB values.
151+
$redBucket = $rgbValue[0] >> $rshift;
152+
$greenBucket = $rgbValue[1] >> $rshift;
153+
$blueBucket = $rgbValue[2] >> $rshift;
151154

152155
return
153-
$rval >= $this->r1 &&
154-
$rval <= $this->r2 &&
155-
$gval >= $this->g1 &&
156-
$gval <= $this->g2 &&
157-
$bval >= $this->b1 &&
158-
$bval <= $this->b2;
156+
$redBucket >= $this->r1 &&
157+
$redBucket <= $this->r2 &&
158+
$greenBucket >= $this->g1 &&
159+
$greenBucket <= $this->g2 &&
160+
$blueBucket >= $this->b1 &&
161+
$blueBucket <= $this->b2;
159162
}
160163

161164
/**

0 commit comments

Comments
 (0)