psd_native 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4bc8f941614e4d6e7a4f3262d95a6d46b81a226f
4
- data.tar.gz: b8085ead0d1a7977ba66806109c31b8e57fa836c
3
+ metadata.gz: 43ce99138b4b79f02a2f05ac620b2cb74572fea3
4
+ data.tar.gz: 2b003b13301a2009dc8ed4668435bd60a77a60ec
5
5
  SHA512:
6
- metadata.gz: 039e4149c2182f105ab85cd8a67442e099edb4bc48f230aa7f9e54021439bdafbef60f7b9d848c074ec0fd2c98b5bab9732c4de60199ce34576ac445ce584382
7
- data.tar.gz: a1910ddae6d3cb053e7c4acafa12cff2125427e8f43832ffb90b79fc34c576960641e3b65f84524aa1996da7b3716eacb0e6e9c90211c791c02dee9907ca22b5
6
+ metadata.gz: 2be538272093186445f346678e4e589715182d37a870f3dc13b075d55d226e835d55fd56e9f21bd17e424e484ee7007ced0f7d0f70fefd09cede853d40f18861
7
+ data.tar.gz: dedc579ccb2b5c9fdbd867c0badab4aebff2bb3e55d2d64c3484d0915b9f2ddee8c281e595d92fe943b3954d90cf6e452ada0f7203b647af9965464d99f4ef50
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require 'rspec/core/rake_task'
4
4
 
5
5
  Rake::ExtensionTask.new('psd_native') do |ext|
6
6
  ext.lib_dir = File.join('lib', 'psd_native')
7
- ext.config_options = '--with-cflags="-std=c99 -openmp"'
7
+ ext.config_options = '--with-cflags="-std=c99"'
8
8
  end
9
9
 
10
10
  Rake::Task['spec'].prerequisites << :compile
@@ -17,4 +17,32 @@ VALUE psd_native_cmyk_to_rgb(VALUE self, VALUE c, VALUE m, VALUE y, VALUE k) {
17
17
 
18
18
  int psd_clamp_int(int n, int low, int high) {
19
19
  return n < low ? low : (n > high ? high : n);
20
+ }
21
+
22
+ int opaque(uint32_t color) {
23
+ return a(color) == 0x000000ff;
24
+ }
25
+
26
+ int transparent(uint32_t color) {
27
+ return a(color) == 0x00000000;
28
+ }
29
+
30
+ uint32_t r(uint32_t color) {
31
+ return (color & 0xff000000) >> 24;
32
+ }
33
+
34
+ uint32_t g(uint32_t color) {
35
+ return (color & 0x00ff0000) >> 16;
36
+ }
37
+
38
+ uint32_t b(uint32_t color) {
39
+ return (color & 0x0000ff00) >> 8;
40
+ }
41
+
42
+ uint32_t a(uint32_t color) {
43
+ return color & 0x000000ff;
44
+ }
45
+
46
+ uint32_t rgba(uint32_t r, uint32_t g, uint32_t b, uint32_t a) {
47
+ return r << 24 | g << 16 | b << 8 | a;
20
48
  }
@@ -3,5 +3,12 @@
3
3
 
4
4
  VALUE psd_native_cmyk_to_rgb(VALUE self, VALUE c, VALUE m, VALUE y, VALUE k);
5
5
  int psd_clamp_int(int n, int low, int high);
6
+ int opaque(uint32_t color);
7
+ int transparent(uint32_t color);
8
+ uint32_t r(uint32_t color);
9
+ uint32_t g(uint32_t color);
10
+ uint32_t b(uint32_t color);
11
+ uint32_t a(uint32_t color);
12
+ uint32_t rgba(uint32_t r, uint32_t g, uint32_t b, uint32_t a);
6
13
 
7
14
  #endif
@@ -0,0 +1,40 @@
1
+ #include "psd_native_ext.h"
2
+
3
+ AlphaValues alpha;
4
+
5
+ VALUE psd_native_compose_normal(VALUE self, VALUE r_fg, VALUE r_bg, VALUE opts) {
6
+ uint32_t fg = FIX2UINT(r_fg);
7
+ uint32_t bg = FIX2UINT(r_bg);
8
+ uint32_t new_r, new_g, new_b;
9
+
10
+ if (opaque(fg) || transparent(bg)) return INT2FIX(fg);
11
+ if (transparent(fg)) return INT2FIX(bg);
12
+
13
+ calculate_alphas(fg, bg, &opts);
14
+
15
+ new_r = blend_channel(r(bg), r(fg), alpha.mix);
16
+ new_g = blend_channel(g(bg), g(fg), alpha.mix);
17
+ new_b = blend_channel(b(bg), b(fg), alpha.mix);
18
+
19
+ return INT2FIX(rgba(new_r, new_g, new_b, alpha.dst));
20
+ }
21
+
22
+ void calculate_alphas(uint32_t fg, uint32_t bg, VALUE *opts) {
23
+ uint32_t opacity = calculate_opacity(opts);
24
+ uint32_t src_alpha = a(fg) * opacity >> 8;
25
+
26
+ alpha.dst = a(bg);
27
+ alpha.mix = (src_alpha << 8) / (src_alpha + ((256 - src_alpha) * alpha.dst >> 8));
28
+ alpha.dst = alpha.dst + ((256 - alpha.dst) * src_alpha >> 8);
29
+ }
30
+
31
+ uint32_t calculate_opacity(VALUE *opts) {
32
+ uint32_t opacity = FIX2UINT(rb_hash_aref(*opts, ID2SYM(rb_intern("opacity"))));
33
+ uint32_t fill_opacity = FIX2UINT(rb_hash_aref(*opts, ID2SYM(rb_intern("fill_opacity"))));
34
+
35
+ return opacity * fill_opacity / 255;
36
+ }
37
+
38
+ uint32_t blend_channel(uint32_t bg, uint32_t fg, uint32_t a) {
39
+ return ((bg << 8) + (fg - bg) * a) >> 8;
40
+ }
@@ -0,0 +1,14 @@
1
+ #ifndef PSD_NATIVE_COMPOSE
2
+ #define PSD_NATIVE_COMPOSE
3
+
4
+ typedef struct AlphaValues {
5
+ int mix;
6
+ int dst;
7
+ } AlphaValues;
8
+
9
+ VALUE psd_native_compose_normal(VALUE self, VALUE fg, VALUE bg, VALUE opts);
10
+ void calculate_alphas(uint32_t fg, uint32_t bg, VALUE *opts);
11
+ uint32_t calculate_opacity(VALUE *opts);
12
+ uint32_t blend_channel(uint32_t bg, uint32_t fg, uint32_t a);
13
+
14
+ #endif
@@ -23,7 +23,11 @@ void Init_psd_native() {
23
23
 
24
24
  // Color functions
25
25
  VALUE Color = rb_define_module_under(PSDNative, "Color");
26
- rb_define_singleton_method(Color, "cmyk_to_rgb", psd_native_cmyk_to_rgb, 4);
26
+ rb_define_module_function(Color, "cmyk_to_rgb", psd_native_cmyk_to_rgb, 4);
27
+
28
+ // Compose functions
29
+ VALUE Compose = rb_define_module_under(PSDNative, "Compose");
30
+ rb_define_module_function(Compose, "normal", psd_native_compose_normal, 3);
27
31
 
28
32
  psd_logger("info", "PSD native mixins enabled!");
29
33
  }
@@ -11,11 +11,12 @@ typedef uint32_t PIXEL;
11
11
  #define BUILD_PIXEL(r, g, b, a) (((PIXEL) (r) << 24) + ((PIXEL) (g) << 16) + ((PIXEL) (b) << 8) + (PIXEL) (a))
12
12
 
13
13
  // Our native mixins
14
- #include "image_mode_rgb.h"
14
+ #include "color.h"
15
+ #include "compose.h"
15
16
  #include "image_mode_cmyk.h"
16
17
  #include "image_mode_greyscale.h"
18
+ #include "image_mode_rgb.h"
17
19
  #include "rle_decoding.h"
18
- #include "color.h"
19
20
 
20
21
  void Init_psd_native();
21
22
  VALUE psd_class();
@@ -0,0 +1,11 @@
1
+ require 'psd'
2
+ require 'psd_native/psd_native'
3
+
4
+ class PSD
5
+ module Compose
6
+ def normal(fg, bg, opts={})
7
+ opts = DEFAULT_OPTS.merge(opts)
8
+ PSDNative::Compose.normal(fg, bg, opts)
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module PSDNative
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
data/lib/psd_native.rb CHANGED
@@ -6,11 +6,12 @@ module PSDNative
6
6
  base::Image.send(:include, PSDNative::ImageMode::CMYK)
7
7
  base::Image.send(:include, PSDNative::ImageMode::Greyscale)
8
8
  base::Image.send(:include, PSDNative::ImageFormat::RLE)
9
+ base::Color.send(:include, PSDNative::Color)
9
10
  end
10
11
  end
11
12
 
12
13
  require "psd_native/version"
13
14
  require "psd_native/psd_native"
14
- require "psd_native/color"
15
+ require "psd_native/compose"
15
16
 
16
17
  PSD.send :include, PSDNative
data/psd_native.gemspec CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.extensions = ["ext/psd_native/extconf.rb"]
21
21
  spec.require_paths = ["lib", "ext"]
22
22
 
23
- spec.add_runtime_dependency "psd", "~> 1.2"
23
+ spec.add_runtime_dependency "psd", ">= 1.4"
24
24
 
25
25
  spec.add_development_dependency "bundler", "~> 1.3"
26
26
  spec.add_development_dependency "rake"
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: psd_native
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan LeFevre
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-16 00:00:00.000000000 Z
11
+ date: 2013-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: psd
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
- version: '1.2'
19
+ version: '1.4'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
- version: '1.2'
26
+ version: '1.4'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -139,6 +139,8 @@ files:
139
139
  - Rakefile
140
140
  - ext/psd_native/color.c
141
141
  - ext/psd_native/color.h
142
+ - ext/psd_native/compose.c
143
+ - ext/psd_native/compose.h
142
144
  - ext/psd_native/extconf.rb
143
145
  - ext/psd_native/image_mode_cmyk.c
144
146
  - ext/psd_native/image_mode_cmyk.h
@@ -151,7 +153,7 @@ files:
151
153
  - ext/psd_native/rle_decoding.c
152
154
  - ext/psd_native/rle_decoding.h
153
155
  - lib/psd_native.rb
154
- - lib/psd_native/color.rb
156
+ - lib/psd_native/compose.rb
155
157
  - lib/psd_native/version.rb
156
158
  - psd_native.gemspec
157
159
  - spec/files/example.psd
@@ -1,13 +0,0 @@
1
- require 'psd'
2
- require 'psd_native/psd_native'
3
-
4
- class PSD
5
- class Color
6
- instance_eval do
7
- alias :old_cmyk_to_rgb :cmyk_to_rgb
8
- def cmyk_to_rgb(*args)
9
- PSDNative::Color.cmyk_to_rgb(*args)
10
- end
11
- end
12
- end
13
- end