Class: Btape::Palette::MedianCut
- Inherits:
-
Object
- Object
- Btape::Palette::MedianCut
- Defined in:
- lib/btape/palette.rb
Overview
Repeatedly splits the colours in use along their widest axis, so that each of the 256 boxes it ends up with holds a similar share of the pixels. Colours a frame leans on get more of the palette than colours it barely touches.
Defined Under Namespace
Classes: Box
Instance Method Summary collapse
- #colours ⇒ Object
-
#initialize(histogram, size: SIZE) ⇒ MedianCut
constructor
A new instance of MedianCut.
Constructor Details
Instance Method Details
#colours ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/btape/palette.rb', line 183 def colours return [[0, 0, 0]] if @entries.empty? boxes = [Box.new(@entries)] while boxes.length < @size index = widest(boxes) break unless index boxes[index, 1] = boxes[index].split end boxes.map(&:colour) end |