psd_native 0.5.0 → 0.6.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: c081770f983b87fa68b32f0a04576c8384bce760
4
- data.tar.gz: aa04b516926a30d512c22fec87f43524a2eca4b5
3
+ metadata.gz: 960643fec9eb4c5832460760e567953247189174
4
+ data.tar.gz: b3000995230c06cad6c95112e30e9be26d70c6aa
5
5
  SHA512:
6
- metadata.gz: 2d8876e7d2981bdecd7701c3d25adca20b8c5e4cebfc00f7f382ae227477972f3e6174ab60daef81f5713da7cbec490e057ae62e120e327221d13bba7968bd6a
7
- data.tar.gz: 03a9c93c7c2ab9d7176909497edf96bcbbb500befeaac3cedc9005ba584bcb072940c9c4dd21b2176d856378c640117811dda1070f4bb789664bd3023d5a9eb9
6
+ metadata.gz: 9da0d02c2b6eb361f3750d44d370ed165af072e03f0ee91a66721da8e516d23213d93e30586630dca03aeba5ffbf4581cf691caf3c480d21401bede582ed46de
7
+ data.tar.gz: 5d2fc658099b074118b6890bcf0608a2be393fef2a415e1f2aba389500f6d6386bdb53c70b8ac0fca87214bc276d250e1015961082507f94260c3aacb36bde1c
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ # gem 'psd', git: 'git@github.com:layervault/psd.rb'
4
+
3
5
  # Specify your gem's dependencies in psd_native.gemspec
4
6
  gemspec
@@ -0,0 +1,58 @@
1
+ #include "psd_native_ext.h"
2
+
3
+ VALUE psd_native_build_preview_blend_pixels(
4
+ VALUE self,
5
+ VALUE blending_mode,
6
+ VALUE layer,
7
+ VALUE base,
8
+ VALUE other,
9
+ VALUE r_offset_x,
10
+ VALUE r_offset_y) {
11
+
12
+ int x, y, base_x, base_y, offset_x, offset_y;
13
+ uint32_t width, height, base_width, base_height;
14
+ VALUE color;
15
+ VALUE Compose = rb_const_get(rb_const_get(rb_cObject, rb_intern("PSD")), rb_intern("Compose"));
16
+
17
+ width = FIX2UINT(rb_funcall(other, rb_intern("width"), 0));
18
+ height = FIX2UINT(rb_funcall(other, rb_intern("height"), 0));
19
+ base_width = FIX2UINT(rb_funcall(base, rb_intern("width"), 0));
20
+ base_height = FIX2UINT(rb_funcall(base, rb_intern("height"), 0));
21
+ offset_x = FIX2INT(r_offset_x);
22
+ offset_y = FIX2INT(r_offset_y);
23
+
24
+ VALUE opacity = rb_hash_new();
25
+ rb_hash_aset(
26
+ opacity,
27
+ ID2SYM(rb_intern("opacity")),
28
+ rb_funcall(layer, rb_intern("opacity"), 0)
29
+ );
30
+
31
+ rb_hash_aset(
32
+ opacity,
33
+ ID2SYM(rb_intern("fill_opacity")),
34
+ rb_funcall(layer, rb_intern("fill_opacity"), 0)
35
+ );
36
+
37
+ for (y = 0; y < height; y++) {
38
+ for (x = 0; x < width; x++) {
39
+ base_x = x + offset_x;
40
+ base_y = y + offset_y;
41
+
42
+ if (base_x < 0 || base_y < 0 || base_x >= base_width || base_y >= base_height) continue;
43
+
44
+ color = rb_funcall(
45
+ Compose,
46
+ rb_intern_str(blending_mode),
47
+ 3,
48
+ rb_funcall(other, rb_intern("[]"), 2, INT2FIX(x), INT2FIX(y)),
49
+ rb_funcall(base, rb_intern("[]"), 2, INT2FIX(base_x), INT2FIX(base_y)),
50
+ opacity
51
+ );
52
+
53
+ rb_funcall(base, rb_intern("[]="), 3, INT2FIX(base_x), INT2FIX(base_y), color);
54
+ }
55
+ }
56
+
57
+ return Qnil;
58
+ }
@@ -0,0 +1,6 @@
1
+ #ifndef PSD_NATIVE_BUILD_PREVIEW
2
+ #define PSD_NATIVE_BUILD_PREVIEW
3
+
4
+ VALUE psd_native_build_preview_blend_pixels(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE);
5
+
6
+ #endif
@@ -12,27 +12,33 @@ VALUE psd_native_combine_rgb_channel(VALUE self) {
12
12
  int channel_count = RARRAY_LENINT(rb_iv_get(self, "@channels_info"));
13
13
 
14
14
  int i, j;
15
- uint32_t val, r, g, b, a;
15
+ uint32_t val, color;
16
+
17
+ int channel_ids[channel_count];
18
+ for (i = 0; i < channel_count; i++) {
19
+ channel_ids[i] = FIX2INT(rb_hash_aref(channels_info[i], ID2SYM(rb_intern("id"))));
20
+ }
16
21
 
17
22
  // Loop through every pixel in the image
18
23
  for (i = 0; i < num_pixels; i += pixel_step) {
19
- r = g = b = 0;
20
- a = 255;
24
+ color = 0x000000ff;
21
25
 
22
26
  // And every channel for every pixel
23
27
  for (j = 0; j < channel_count; j++) {
28
+ if (channel_ids[j] == -2) continue;
29
+
24
30
  val = FIX2UINT(channel_data[i + (channel_length * j)]);
25
31
 
26
32
  // Get the hash containing channel info
27
- switch (FIX2INT(rb_hash_aref(channels_info[j], ID2SYM(rb_intern("id"))))) {
28
- case -1: a = val; break;
29
- case 0: r = val; break;
30
- case 1: g = val; break;
31
- case 2: b = val; break;
33
+ switch (channel_ids[j]) {
34
+ case -1: color = (color & 0xffffff00) | val; break; // A
35
+ case 0: color = (color & 0x00ffffff) | (val << 24); break; // R
36
+ case 1: color = (color & 0xff00ffff) | (val << 16); break; // G
37
+ case 2: color = (color & 0xffff00ff) | (val << 8); break; // B
32
38
  }
33
39
  }
34
40
 
35
- rb_ary_push(rb_iv_get(self, "@pixel_data"), INT2FIX(BUILD_PIXEL(r, g, b, a)));
41
+ rb_ary_push(rb_iv_get(self, "@pixel_data"), INT2FIX(color));
36
42
  }
37
43
 
38
44
  return Qnil;
@@ -1,6 +1,12 @@
1
1
  #include "psd_native_ext.h"
2
2
 
3
+ static VALUE psd_class;
4
+ static VALUE logger;
5
+
3
6
  void Init_psd_native() {
7
+ psd_class = rb_const_get(rb_cObject, rb_intern("PSD"));
8
+ logger = rb_funcall(psd_class, rb_intern("logger"), 0);
9
+
4
10
  VALUE PSDNative = rb_define_module("PSDNative");
5
11
  VALUE ImageMode = rb_define_module_under(PSDNative, "ImageMode");
6
12
 
@@ -49,15 +55,22 @@ void Init_psd_native() {
49
55
  VALUE ClippingMask = rb_define_module_under(PSDNative, "ClippingMask");
50
56
  rb_define_method(ClippingMask, "apply", psd_native_clipping_mask_apply, 0);
51
57
 
52
- psd_logger("info", "PSD native mixins enabled!");
53
- }
58
+ // Build preview
59
+ VALUE Node = rb_define_module_under(PSDNative, "Node");
60
+ VALUE BuildPreview = rb_define_module_under(Node, "BuildPreview");
61
+ rb_define_private_method(BuildPreview, "blend_pixels!", psd_native_build_preview_blend_pixels, 6);
62
+
63
+ // Util
64
+ VALUE Util = rb_define_module_under(PSDNative, "Util");
65
+ rb_define_method(Util, "pad2", psd_native_util_pad2, 1);
66
+ rb_define_method(Util, "pad4", psd_native_util_pad4, 1);
67
+ rb_define_method(Util, "clamp", psd_native_util_clamp, 3);
54
68
 
55
- VALUE psd_class() {
56
- return rb_const_get(rb_cObject, rb_intern("PSD"));
69
+ psd_logger("info", "PSD native mixins enabled!");
57
70
  }
58
71
 
59
72
  void psd_logger(char* level, char* message) {
60
- rb_funcall(rb_funcall(psd_class(), rb_intern("logger"), 0), rb_intern(level), 1, rb_str_new2(message));
73
+ rb_funcall(logger, rb_intern(level), 1, rb_str_new2(message));
61
74
  }
62
75
 
63
76
  VALUE psd_file(VALUE self) {
@@ -4,12 +4,14 @@
4
4
  #include "ruby.h"
5
5
 
6
6
  #define RSTRING_NOT_MODIFIED
7
+ #define PSD_CONCURRENCY 4
7
8
 
8
9
  // Pixels use 32 bits unsigned integers
9
10
  // We borrow this from OilyPNG
10
11
  typedef uint32_t PIXEL;
11
12
 
12
13
  // Our native mixins
14
+ #include "util.h"
13
15
  #include "color.h"
14
16
  #include "clipping_mask.h"
15
17
  #include "compose.h"
@@ -17,9 +19,10 @@ typedef uint32_t PIXEL;
17
19
  #include "image_mode_greyscale.h"
18
20
  #include "image_mode_rgb.h"
19
21
  #include "rle_decoding.h"
22
+ #include "build_preview.h"
20
23
 
21
24
  void Init_psd_native();
22
- VALUE psd_class();
25
+ // VALUE psd_class();
23
26
  void psd_logger(char* level, char* message);
24
27
  VALUE psd_file(VALUE self);
25
28
  int psd_file_tell(VALUE self);
@@ -0,0 +1,17 @@
1
+ #include "psd_native_ext.h"
2
+
3
+ VALUE psd_native_util_pad2(VALUE self, VALUE i) {
4
+ return INT2FIX((FIX2INT(i) + 1) & ~0x01);
5
+ }
6
+
7
+ VALUE psd_native_util_pad4(VALUE self, VALUE i) {
8
+ return INT2FIX(((FIX2INT(i) + 4) & ~0x03) - 1);
9
+ }
10
+
11
+ VALUE psd_native_util_clamp(VALUE self, VALUE r_num, VALUE r_min, VALUE r_max) {
12
+ int num = FIX2INT(r_num);
13
+ int min = FIX2INT(r_min);
14
+ int max = FIX2INT(r_max);
15
+
16
+ return num > max ? r_max : (num < min ? r_min : r_num);
17
+ }
@@ -0,0 +1,8 @@
1
+ #ifndef PSD_NATIVE_UTIL
2
+ #define PSD_NATIVE_UTIL
3
+
4
+ VALUE psd_native_util_pad2(VALUE self, VALUE i);
5
+ VALUE psd_native_util_pad4(VALUE self, VALUE i);
6
+ VALUE psd_native_util_clamp(VALUE self, VALUE num, VALUE min, VALUE max);
7
+
8
+ #endif
@@ -1,3 +1,3 @@
1
1
  module PSDNative
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
data/lib/psd_native.rb CHANGED
@@ -7,6 +7,8 @@ module PSDNative
7
7
  base::Image.send(:include, PSDNative::ImageMode::Greyscale)
8
8
  base::Image.send(:include, PSDNative::ImageFormat::RLE)
9
9
  base::Color.send(:include, PSDNative::Color)
10
+ base::Node.send(:include, PSDNative::Node::BuildPreview)
11
+ base::Util.extend PSDNative::Util
10
12
 
11
13
  base::ClippingMask.class_eval do
12
14
  remove_method :apply
data/spec/util_spec.rb ADDED
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Util' do
4
+ it "pad2's correctly" do
5
+ expect(PSD::Util.pad2(0)).to eq 0
6
+ expect(PSD::Util.pad2(1)).to eq 2
7
+ end
8
+
9
+ # Note, this pad4 is weird but this is expected results
10
+ it "pad4's correctly" do
11
+ expect(PSD::Util.pad4(0)).to eq 3
12
+ expect(PSD::Util.pad4(1)).to eq 3
13
+ expect(PSD::Util.pad4(2)).to eq 3
14
+ end
15
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: psd_native
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.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-11-18 00:00:00.000000000 Z
11
+ date: 2013-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: psd
@@ -137,6 +137,8 @@ files:
137
137
  - LICENSE.txt
138
138
  - README.md
139
139
  - Rakefile
140
+ - ext/psd_native/build_preview.c
141
+ - ext/psd_native/build_preview.h
140
142
  - ext/psd_native/clipping_mask.c
141
143
  - ext/psd_native/clipping_mask.h
142
144
  - ext/psd_native/color.c
@@ -154,6 +156,8 @@ files:
154
156
  - ext/psd_native/psd_native_ext.h
155
157
  - ext/psd_native/rle_decoding.c
156
158
  - ext/psd_native/rle_decoding.h
159
+ - ext/psd_native/util.c
160
+ - ext/psd_native/util.h
157
161
  - lib/psd_native.rb
158
162
  - lib/psd_native/compose.rb
159
163
  - lib/psd_native/version.rb
@@ -167,6 +171,7 @@ files:
167
171
  - spec/image_spec.rb
168
172
  - spec/psd_spec.rb
169
173
  - spec/spec_helper.rb
174
+ - spec/util_spec.rb
170
175
  homepage: http://cosmos.layervault.com/psdrb.html
171
176
  licenses:
172
177
  - MIT
@@ -188,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
188
193
  version: '0'
189
194
  requirements: []
190
195
  rubyforge_project:
191
- rubygems_version: 2.0.8
196
+ rubygems_version: 2.1.11
192
197
  signing_key:
193
198
  specification_version: 4
194
199
  summary: Native C mixins to speed up the slowest parts of PSD.rb
@@ -202,3 +207,4 @@ test_files:
202
207
  - spec/image_spec.rb
203
208
  - spec/psd_spec.rb
204
209
  - spec/spec_helper.rb
210
+ - spec/util_spec.rb