Skip to content

Commit

Permalink
Fix eight digit hex to RGB
Browse files Browse the repository at this point in the history
  • Loading branch information
evanleck committed Sep 13, 2021
1 parent 6a1d902 commit b7df429
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.org
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
* Kodachroma changelog

** 1.0.1

Fix eight digit hexidecimal conversion to RGB. Fixes [[https://github.com/jfairbank/chroma/pull/30][chroma#30]].

** 1.0.0

Initial release of Kodachroma which is effectively a copy and rename of the
Expand Down
4 changes: 2 additions & 2 deletions lib/kodachroma/color/serializers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ def to_basic_hex(allow_3 = false)

def to_basic_hex8
[
to_2char_hex(alpha * 255),
to_2char_hex(@rgb.r),
to_2char_hex(@rgb.g),
to_2char_hex(@rgb.b)
to_2char_hex(@rgb.b),
to_2char_hex(alpha * 255)
].join
end

Expand Down
2 changes: 1 addition & 1 deletion lib/kodachroma/rgb_generator/from_hex_string_values.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def from_hex6(format, r, g, b)
# @param g [String] green value
# @param b [String] blue value
# @param a [String] alpha value
def from_hex8(format, a, r, g, b)
def from_hex8(format, r, g, b, a)
new(format || :hex8, r, g, b, a)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/kodachroma/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: true
module Kodachroma
VERSION = '1.0.0'
VERSION = '1.0.1'
end
4 changes: 2 additions & 2 deletions spec/color/attributes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
describe '#alpha' do
it 'returns the correct alpha value' do
expect(Kodachroma.paint('rgba(255, 0, 0, 0.75)').alpha).to eq 0.75
expect(Kodachroma.paint('#80ff0000').alpha).to be_within(0.01).of(0.5)
expect(Kodachroma.paint('#80ff0000').alpha).to eq 0
expect(Kodachroma.paint('transparent').alpha).to eq 0
expect(Kodachroma.paint('hsla(0, 100%, 50%, 0').alpha).to eq 0
expect(Kodachroma.paint('hsla(0, 100%, 50%, 0)').alpha).to eq 0
expect(red.alpha).to eq 1
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/color/serializers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@

describe '#to_hex8' do
it 'returns the hex8 string' do
expect(green.to_hex8).to eq('#ff008000')
expect(blue.to_hex8).to eq('#800000ff')
expect(green.to_hex8).to eq('#008000ff')
expect(blue.to_hex8).to eq('#0000ff80')
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/kodachroma/paint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
end

it 'sets alpha' do
expect(described_class.paint(hex).alpha).to be_within(0.1).of(0.5)
expect(described_class.paint(hex).alpha).to eq(0)
end
end

Expand Down

0 comments on commit b7df429

Please sign in to comment.