falu 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a596b1571462637d99273b711c2489641d3f1409
4
- data.tar.gz: 91424364b332d0ea3b345bf53c9406ef65c2db0f
3
+ metadata.gz: f08793b49c9cd82d6a486fd2903dc1041a1a2f73
4
+ data.tar.gz: 309a1a89a69629163ad945f854c1577dd6607d34
5
5
  SHA512:
6
- metadata.gz: ed9b2293b5f5efb04d6d65597f47ea15773011138d4705dd056879c6e367fd7966ab531e996c22d3318fea9d2e5a349811ae4f2c60a78b178d935debf3304297
7
- data.tar.gz: f3642a9ec4e03309a3ab1ea6e15216f3d09b7128d932c1d61deef1a7c399145480143d2ae2ea28ac3fca56aed7e2f5a8809f80e970632d0f63e9c64e8ee35aea
6
+ metadata.gz: b2ed04569779b47dddf8782a6bc08aba512300bb13b111abbf5ab890844d0bc906ee3b8e2db9537381a3d80d0594a04c0548b7ab4068d5e40487af9f2e203db1
7
+ data.tar.gz: 704decaa5d473ee1c5516a332b70d211896ec8af94396c7f9bdd7a77de207491853b4e0ad610a532ccdf99069d37be63bfa95c563bc43c68a7209090dc0ddb94
@@ -1,5 +1,6 @@
1
1
  module Falu
2
2
  class DitheredPalette < ImagePalette
3
+
3
4
  delegate :colors, to: :configuration
4
5
 
5
6
  def initialize(image, swatches=nil, **opts)
@@ -8,8 +9,31 @@ module Falu
8
9
  end
9
10
 
10
11
  def swatches
11
- @swatches = image.scale(scale).dither(colors).sample(0, 0, size: size, sample: sample).map { |swatch| Falu::Swatch.new(*swatch) } if @swatches.empty?
12
+ if @swatches.empty?
13
+ @swatches = image.dither(colors, scale: (colors*10), unique: true).sample(0, 0, size: 10, sample: true).map { |swatch| Falu::Swatch.new(swatch[0], 0) }
14
+ image.dither(colors, scale: scale).sample(0, 0, size: size, sample: sample).each do |clr|
15
+ color = Falu::Color.new(clr[0])
16
+ exact = @swatches.index { |s| s.color.hex.to_s == color.hex.to_s }
17
+ unless exact.nil?
18
+ @swatches[exact] += clr[1]
19
+ next
20
+ end
21
+
22
+ @swatches.sort { |a,b| b.count <=> a.count }.each_with_index do |swatch, s|
23
+ if [:red, :green, :blue].all? { |c| (swatch.color.rgb.send(c) - color.rgb.send(c)).abs <= 10 }
24
+ @swatches[s] += clr[1]
25
+ break
26
+ end
27
+ end
28
+ end
29
+ end
12
30
  @swatches
13
31
  end
32
+
33
+ def as_json(options={})
34
+ super(options).merge({
35
+ colors: colors
36
+ })
37
+ end
14
38
  end
15
39
  end
@@ -1,5 +1,17 @@
1
1
  module Falu
2
2
  class ImagePalette < Palette
3
+ class << self
4
+ def dump(palette)
5
+ palette.as_json
6
+ end
7
+
8
+ def load(json)
9
+ return if json.nil?
10
+ json.symbolize_keys!
11
+ new(json.delete(:image), json.delete(:swatches), **json)
12
+ end
13
+ end
14
+
3
15
  delegate :sample, :scale, :size, to: :configuration
4
16
 
5
17
  def initialize(image, swatches=nil, **opts)
@@ -17,5 +29,13 @@ module Falu
17
29
  @swatches = image.scale(scale).sample(0, 0, size: size, sample: sample).map { |swatch| Falu::Swatch.new(*swatch) } if @swatches.empty?
18
30
  @swatches
19
31
  end
32
+
33
+ def as_json(options={})
34
+ super(options).merge({
35
+ sample: sample,
36
+ scale: scale,
37
+ size: size
38
+ })
39
+ end
20
40
  end
21
41
  end
@@ -2,7 +2,7 @@ module Falu
2
2
  module Version
3
3
  MAJOR = '0'
4
4
  MINOR = '0'
5
- PATCH = '2'
5
+ PATCH = '3'
6
6
  VERSION = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
 
8
8
  class << self
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: falu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Rebec