potracer 1.0.4 → 1.0.5
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.
- data/ext/potracer/potracer.c +34 -5
- data/lib/potracer.rb +10 -5
- metadata +4 -4
data/ext/potracer/potracer.c
CHANGED
@@ -5,6 +5,24 @@
|
|
5
5
|
|
6
6
|
#include "potracer.h"
|
7
7
|
|
8
|
+
static int
|
9
|
+
is_colored (char *str, int row, int col, int cols, int size)
|
10
|
+
{
|
11
|
+
int i, start;
|
12
|
+
unsigned char v, max, min;
|
13
|
+
|
14
|
+
start = ((row * cols * size) + (col * size));
|
15
|
+
max = min = str[start];
|
16
|
+
|
17
|
+
for (i = 0; i < size; i++) {
|
18
|
+
v = str[start + i];
|
19
|
+
min = min < v ? min : v;
|
20
|
+
max = max > v ? max : v;
|
21
|
+
}
|
22
|
+
|
23
|
+
return ((min + max) / 2.0) < 128;
|
24
|
+
}
|
25
|
+
|
8
26
|
static void
|
9
27
|
rb_progress (double progress, void *callback)
|
10
28
|
{
|
@@ -210,7 +228,8 @@ bitmap_init(int argc, VALUE *argv, VALUE klass)
|
|
210
228
|
static VALUE
|
211
229
|
bitmap_new (int argc, VALUE *argv, VALUE klass)
|
212
230
|
{
|
213
|
-
int i, j;
|
231
|
+
int i, j, m, s;
|
232
|
+
unsigned char *bits;
|
214
233
|
potrace_bitmap_t *bm;
|
215
234
|
VALUE bdata, row;
|
216
235
|
|
@@ -221,10 +240,20 @@ bitmap_new (int argc, VALUE *argv, VALUE klass)
|
|
221
240
|
bm->map = ALLOC_N(potrace_word, bm->dy * bm->h * BM_WORDSIZE);
|
222
241
|
|
223
242
|
if (argc > 2) {
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
243
|
+
if (T_STRING == TYPE(argv[2])) {
|
244
|
+
bits = StringValuePtr(argv[2]);
|
245
|
+
m = strlen(StringValuePtr(argv[3]));
|
246
|
+
for (i = 0; i < bm->h; i++) {
|
247
|
+
for (j = 0; j < bm->w; j++) {
|
248
|
+
BM_PUT(bm, j, i, is_colored(bits, i, j, bm->w, m));
|
249
|
+
}
|
250
|
+
}
|
251
|
+
} else {
|
252
|
+
for (i = 0; i < bm->h; i++) {
|
253
|
+
row = rb_ary_entry(argv[2], (long)i);
|
254
|
+
for (j = 0; j < bm->w; j++) {
|
255
|
+
BM_PUT(bm, j, i, NUM2INT(rb_ary_entry(row, (long)j)));
|
256
|
+
}
|
228
257
|
}
|
229
258
|
}
|
230
259
|
}
|
data/lib/potracer.rb
CHANGED
@@ -10,13 +10,18 @@ module Potracer
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
def self.bitmap(bmp, &block)
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
def self.bitmap(bmp, width=nil, height=nil, map='RGB', &block)
|
14
|
+
width ||= bmp.map {|r| r.length}.max
|
15
|
+
height ||= bmp.length
|
16
|
+
|
17
|
+
unless bmp.is_a? String
|
18
|
+
bmp.map! {|r| r.fill(0, r.length, width - r.length)}
|
19
|
+
end
|
20
|
+
|
17
21
|
trace = self.new
|
18
22
|
params = Potracer::Params.new
|
19
|
-
bits = Potracer::Bitmap.new(width, height, bmp)
|
23
|
+
bits = Potracer::Bitmap.new(width, height, bmp, map)
|
24
|
+
|
20
25
|
if block_given?
|
21
26
|
trace.trace(bits, params, &block)
|
22
27
|
else
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: potracer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-02-22 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Ruby bindings for the potrace library.
|
15
15
|
email: k.parnell@gmail.com
|
@@ -20,9 +20,9 @@ extra_rdoc_files: []
|
|
20
20
|
files:
|
21
21
|
- lib/potracer.rb
|
22
22
|
- ext/potracer/extconf.h
|
23
|
-
- ext/potracer/potracer.h
|
24
|
-
- ext/potracer/potracer.c
|
25
23
|
- ext/potracer/extconf.rb
|
24
|
+
- ext/potracer/potracer.c
|
25
|
+
- ext/potracer/potracer.h
|
26
26
|
homepage: https://github.com/kparnell/potracer
|
27
27
|
licenses: []
|
28
28
|
post_install_message:
|