psd_native 1.0.1 → 1.1.0

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: c97817e8dc5cc4bc5c152271dec5220be1c72733
4
- data.tar.gz: 33ce557f4e155bcabd6e8b6bc33207799e7094a7
3
+ metadata.gz: ba6252238c0a42264e81b13c9ad094d459f937cc
4
+ data.tar.gz: a9d7254957111c606e550f1e05217070075c1bc2
5
5
  SHA512:
6
- metadata.gz: 8616aa6ff2eba454d41b0ea8311f7e815ddbda88bf9689f06a0ecf95a1d10c6f6acc7435bb2ba505c041108e33845aa5f978c350c4169e920856795f960ff1bb
7
- data.tar.gz: 8f0ea25002ae6127a6ddc295e0cca45117061d89b82c226d6ed1952563a5a96baedaf97b2d4ca1c2fa3351bc8e251fda7480b5a25597ed6630f96f5633f89f94
6
+ metadata.gz: 51b58c58785979aff5206139ba2ba1bdfdb987e464bed797f64922c058c5fd9d286b9b205343f8eee705345b5f2e2a7338ce80bd23f499418cd88d1e7fecc0c4
7
+ data.tar.gz: e0fb65e4287bb98cd45362549cebb806e0a3450979756fe20d3b34801f27110812a2093c863fff411ad5f18092a34b11e1570023c88950c2addbc8c998037b6f
@@ -0,0 +1,48 @@
1
+ #include "psd_native_ext.h"
2
+
3
+ VALUE psd_native_mask_apply_bang(VALUE self) {
4
+ psd_logger("debug", "Applying mask with native code");
5
+
6
+ int doc_width = FIX2INT(rb_iv_get(self, "@doc_width"));
7
+ int doc_height = FIX2INT(rb_iv_get(self, "@doc_height"));
8
+
9
+ VALUE layer = rb_iv_get(self, "@layer");
10
+ VALUE canvas = rb_iv_get(self, "@canvas");
11
+ VALUE mask = rb_funcall(layer, rb_intern("mask"), 0);
12
+ VALUE *mask_data = RARRAY_PTR(rb_funcall(rb_funcall(layer, rb_intern("image"), 0), rb_intern("mask_data"), 0));
13
+
14
+ int mask_height = FIX2INT(rb_funcall(mask, rb_intern("height"), 0));
15
+ int mask_width = FIX2INT(rb_funcall(mask, rb_intern("width"), 0));
16
+ int mask_left = FIX2INT(rb_funcall(mask, rb_intern("left"), 0));
17
+ int mask_top = FIX2INT(rb_funcall(mask, rb_intern("top"), 0));
18
+
19
+ int layer_left = FIX2INT(rb_funcall(layer, rb_intern("left"), 0));
20
+ int layer_top = FIX2INT(rb_funcall(layer, rb_intern("top"), 0));
21
+
22
+ PIXEL color;
23
+ int x, y, doc_x, doc_y, layer_x, layer_y, alpha;
24
+ int i = 0;
25
+ for (y = 0; y < mask_height; y++) {
26
+ for (x = 0; x < mask_width; x++) {
27
+ doc_x = mask_left + x;
28
+ doc_y = mask_top + y;
29
+ layer_x = doc_x - layer_left;
30
+ layer_y = doc_y - layer_top;
31
+
32
+ color = FIX2UINT(rb_funcall(canvas, rb_intern("[]"), 2, INT2FIX(layer_x), INT2FIX(layer_y)));
33
+
34
+ if (doc_x < 0 || doc_x >= doc_width || doc_y < 0 || doc_y > doc_height) {
35
+ alpha = 0;
36
+ } else {
37
+ alpha = mask_data[i];
38
+ }
39
+
40
+ color = (color & 0xffffff00) | (A(color) * alpha / 255);
41
+ rb_funcall(canvas, rb_intern("[]="), 3, INT2FIX(layer_x), INT2FIX(layer_y), INT2FIX(color));
42
+
43
+ i++;
44
+ }
45
+ }
46
+
47
+ return Qnil;
48
+ }
@@ -0,0 +1,6 @@
1
+ #ifndef PSD_NATIVE_MASK
2
+ #define PSD_NATIVE_MASK
3
+
4
+ VALUE psd_native_mask_apply_bang(VALUE self);
5
+
6
+ #endif
@@ -63,6 +63,10 @@ void Init_psd_native() {
63
63
  VALUE ClippingMask = rb_define_module_under(Renderer, "ClippingMask");
64
64
  rb_define_method(ClippingMask, "apply!", psd_native_clipping_mask_apply_bang, 0);
65
65
 
66
+ // Mask
67
+ VALUE Mask = rb_define_module_under(Renderer, "Mask");
68
+ rb_define_method(Mask, "apply!", psd_native_mask_apply_bang, 0);
69
+
66
70
  // Blender
67
71
  VALUE Blender = rb_define_module_under(Renderer, "Blender");
68
72
  rb_define_method(Blender, "compose!", psd_native_blender_compose_bang, 0);
@@ -14,6 +14,7 @@ typedef uint32_t PIXEL;
14
14
  #include "file.h"
15
15
  #include "color.h"
16
16
  #include "clipping_mask.h"
17
+ #include "mask.h"
17
18
  #include "compose.h"
18
19
  #include "image_mode_cmyk.h"
19
20
  #include "image_mode_greyscale.h"
@@ -1,3 +1,3 @@
1
1
  module PSDNative
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  end
data/lib/psd_native.rb CHANGED
@@ -16,6 +16,11 @@ module PSDNative
16
16
  end
17
17
  base::Renderer::ClippingMask.send(:include, PSDNative::Renderer::ClippingMask)
18
18
 
19
+ base::Renderer::Mask.class_eval do
20
+ remove_method :apply!
21
+ end
22
+ base::Renderer::Mask.send(:include, PSDNative::Renderer::Mask)
23
+
19
24
  base::Renderer::Blender.class_eval do
20
25
  remove_method :compose!
21
26
  end
data/psd_native.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.extensions = ["ext/psd_native/extconf.rb"]
22
22
  spec.require_paths = ["lib", "ext"]
23
23
 
24
- spec.add_runtime_dependency "psd", ">= 2.0.0"
24
+ spec.add_runtime_dependency "psd", "~> 2.1.1"
25
25
  spec.add_runtime_dependency "oily_png", "~> 1.1"
26
26
 
27
27
  spec.add_development_dependency "bundler", "~> 1.3"
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: 1.0.1
4
+ version: 1.1.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: 2014-02-21 00:00:00.000000000 Z
11
+ date: 2014-03-07 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: 2.0.0
19
+ version: 2.1.1
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: 2.0.0
26
+ version: 2.1.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: oily_png
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -158,6 +158,8 @@ files:
158
158
  - ext/psd_native/image_mode_rgb.h
159
159
  - ext/psd_native/layer_raw.c
160
160
  - ext/psd_native/layer_raw.h
161
+ - ext/psd_native/mask.c
162
+ - ext/psd_native/mask.h
161
163
  - ext/psd_native/psd_native_ext.c
162
164
  - ext/psd_native/psd_native_ext.h
163
165
  - ext/psd_native/rle_decoding.c