Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/miro/dominant_colors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ def downsample_and_histogram

def parse_result(hstring)
hstring.scan(/(\d*):.*(#[0-9A-Fa-f]*)/).collect do |match|
[match[0].to_i, eval("Color::#{Miro.options[:quantize].upcase}").from_html(match[1])]
colors = match[1].slice(0..6)
[match[0].to_i, eval("Color::#{Miro.options[:quantize].upcase}").from_html(colors)]
end
end

Expand Down
12 changes: 11 additions & 1 deletion spec/miro/dominant_colors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

describe Miro::DominantColors do
context "colors_group method" do
let(:command) { double('sommang', run: true) }
let(:subject) { Miro::DominantColors.new('/path/to/file') }
let(:mock_source_image) { double('file', :path => '/path/to/source_image').as_null_object }
let(:mock_downsampled_image) { double('file', :path => '/path/to/downsampled_image').as_null_object }
Expand All @@ -22,7 +23,7 @@

before do
Miro.stub(:histogram?).and_return(false)
Cocaine::CommandLine.stub(:new).and_return(double('command', :run => true))
Cocaine::CommandLine.stub(:new).and_return(command)
ChunkyPNG::Image.stub(:from_file).and_return(chunky_png_results)
end

Expand Down Expand Up @@ -196,6 +197,15 @@
it "should end with the less used color" do
subject.histogram.last[1].should == Color::RGB.from_html('#8F0074')
end

context 'command returns invalid colors' do
let(:mixed_rgb_rgba) { ['#00112233', '#00112233FF'] }
let(:command) { double('sommang', run: mixed_rgb_rgba) }

it 'keeps the correct number of colors for processing' do
subject.histogram
end
end
end

describe "#to_hex" do
Expand Down